Created
January 21, 2015 12:58
-
-
Save petermd/6fc3f211639287eb7c83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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