Created
January 29, 2013 08:04
-
-
Save jramb/4662593 to your computer and use it in GitHub Desktop.
Luhn in Clojure
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- digits [n] | |
(map read-string (re-seq #"[0-9]" (str n)))) | |
(defn luhn? [n] | |
(zero? (mod | |
(reduce + | |
(digits (reduce str | |
(map * (cycle [1 2]) (reverse (digits n)))))) | |
10))) | |
(map luhn? | |
[49927398716 49927398717 1234567812345678 1234567812345670]) | |
;;=> (true false false true) | |
;; also: http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Clojure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment