Skip to content

Instantly share code, notes, and snippets.

@snt
Created November 28, 2013 08:45
Show Gist options
  • Select an option

  • Save snt/7688917 to your computer and use it in GitHub Desktop.

Select an option

Save snt/7688917 to your computer and use it in GitHub Desktop.
(defn luhn-check-digit [numStr]
(let [char-to-integer (fn [c] (Integer/parseInt (str c)))
prod-tuple (fn [t] (* (t 0) (t 1)))
sum-digits (fn [n] (if (> n 9) (- n 9) n))]
(->> numStr
reverse
(map char-to-integer)
(zip (cycle [2 1]))
(map (comp sum-digits prod-tuple))
(reduce +)
(#(mod % 10))
(- 10))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment