Created
May 19, 2016 00:51
-
-
Save pataprogramming/e644c920f6d2bcafc8a7c0f6b7949c47 to your computer and use it in GitHub Desktop.
Luhn Kata
This file contains 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
(ns luhn.core) | |
(defn sum-digits [n] | |
(->> n | |
str | |
(mapv (comp #(- % 48) int)) | |
(reduce +))) | |
(defn luhn-checksum [n] | |
(->> n | |
str | |
reverse | |
(mapv (comp #(- % 48) int)) | |
(map-indexed #(if (odd? %1) | |
(let [v (* 2 %2)] | |
(if (> v 9) (sum-digits v) v)) | |
%2)) | |
(reduce +) | |
(#(= (mod % 10) 0)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment