Skip to content

Instantly share code, notes, and snippets.

@pataprogramming
Created May 19, 2016 00:51
Show Gist options
  • Save pataprogramming/e644c920f6d2bcafc8a7c0f6b7949c47 to your computer and use it in GitHub Desktop.
Save pataprogramming/e644c920f6d2bcafc8a7c0f6b7949c47 to your computer and use it in GitHub Desktop.
Luhn Kata
(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