Skip to content

Instantly share code, notes, and snippets.

@petermd
Created January 21, 2015 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petermd/6fc3f211639287eb7c83 to your computer and use it in GitHub Desktop.
Save petermd/6fc3f211639287eb7c83 to your computer and use it in GitHub Desktop.
(defn sum-digits [num]
(+ (quot num 10) (mod num 10)))
(defn sum-doubleeven [idx num]
(sum-digits (if (even? idx) num (* num 2))))
(defn luhn? [num]
(zero? (mod (reduce + (map-indexed sum-doubleeven (reverse num))) 10)))
(defn test-luhn []
(map luhn? ["49927398716","49927398717","1234567812345678","1234567812345670"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment