Thank you for clarifying. I have now understood.
It is actually a really neat solution it basically reduces the code to just two functions.
(defn is-valid-modified? [number] (let [first-four (quot number 10) check-sum (rem number 10)] (-> first-four (mod 7) (- check-sum) (mod 7) (= 0)))) user> (is-valid-modified? 10006) true user> (is-valid-modified? 99993) true user> (is-valid-modified? 99998) false user> (is-valid-modified? 12342) true user> (is-valid-modified? 11697) true
(defn validate-scratch-card [card-number] (let [f (comp is-valid-modified? #(Integer/parseInt %))] (->> (string/split card-number #"(-|\s)") (map f) (every? true?)))) user> (validate-scratch-card "10006 12342 00081 99998") false user> (validate-scratch-card "10006 12342 00081 99993") true
I have learnt something, thank you.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you for clarifying. I have now understood.
It is actually a really neat solution it basically reduces the code to just two functions.
I have learnt something, thank you.