Showing entries 1 to 1
Displaying posts with tag: Scheme (reset)
Luhn (scheme implementation)
(define luhn-check
  (lambda (ccn)
    (define csum 0)
    (define num 0)

    (do ((i (string-length ccn) (- i 1)))
      ((<= i 0) (print csum))

      (set! num (string->number (substring ccn (- i 1) i)))
      (if (> (modulo i 2) 0)
                        (begin

                         (set! num ( * 2 num))
                         (if (> num 9) (set! num (- num 9)))))

      (set! csum (+ num csum))
      )))
;; test case
(luhn-check “4561261212345467″)



And here is implemented with MySQL.

Showing entries 1 to 1