Last active
August 7, 2018 17:55
-
-
Save knjname/f1f7ac337052a9439db5e00a1c3d47e8 to your computer and use it in GitHub Desktop.
See http://qiita.com/qube81/items/fa6ef94d3c8615b0ce64 for details.
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
(defn | |
validate-my-number [mynumber] | |
(and (re-matches #"^\d{12}$" mynumber) | |
(let [digits (map int mynumber) | |
[xs [check_digit]] (split-at 11 digits) | |
each_digit_fn (fn [num idx] (* num (if (<= idx 6) (+ idx 1) (- idx 5)))) | |
calculated_digit (as-> xs <> | |
(reverse <>) | |
(map each_digit_fn <> (iterate inc 1)) | |
(reduce + <>) | |
(mod <> 11) | |
(if (<= <> 1) 0 (- 11 <>)))] | |
(= check_digit calculated_digit)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment