Guest User

Untitled

a guest
May 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. ;;;;;
  2. ;; Calulating ISBN-13 check digit
  3. ;;;;;
  4.  
  5. (defn calc-isbn-check-digit
  6. ""
  7. [#^String isbn-code]
  8. (let [split-code (map #(Character/digit % 10) isbn-code)
  9. partitioned-code (partition 2 split-code)
  10. first-sum (reduce + (map #(first %) partitioned-code))
  11. second-sum (reduce + (map #(* 3 (second %)) partitioned-code))
  12. final-sum (+ first-sum second-sum)
  13. check-digit (- 10 (mod final-sum 10))]
  14. check-digit))
  15.  
  16. ;;; Cleaner/Elegant Solution
  17.  
  18. (defn calc-isbn-check-digit-redux
  19. ""
  20. [#^String isbn-code]
  21. (let [split-code (map #(Character/digit % 10) isbn-code)
  22. final-sum (reduce + (map * split-code (cycle [1 3])))]
  23. (- 10 (mod final-sum 10))))
Add Comment
Please, Sign In to add comment