Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;
- ;; Calulating ISBN-13 check digit
- ;;;;;
- (defn calc-isbn-check-digit
- ""
- [#^String isbn-code]
- (let [split-code (map #(Character/digit % 10) isbn-code)
- partitioned-code (partition 2 split-code)
- first-sum (reduce + (map #(first %) partitioned-code))
- second-sum (reduce + (map #(* 3 (second %)) partitioned-code))
- final-sum (+ first-sum second-sum)
- check-digit (- 10 (mod final-sum 10))]
- check-digit))
- ;;; Cleaner/Elegant Solution
- (defn calc-isbn-check-digit-redux
- ""
- [#^String isbn-code]
- (let [split-code (map #(Character/digit % 10) isbn-code)
- final-sum (reduce + (map * split-code (cycle [1 3])))]
- (- 10 (mod final-sum 10))))
Add Comment
Please, Sign In to add comment