Created
February 8, 2020 21:23
-
-
Save celwell/43f6a3c38087287da3d5312320460fb0 to your computer and use it in GitHub Desktop.
Solution to 4Clojure #92 - Read Roman Numerals
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
(fn [roman-str] | |
(let [letter-val {\0 0 ;; for padding last tuple | |
\I 1, \V 5, \X 10, \L 50 | |
\C 100, \D 500, \M 1000} | |
letter-tuple->dec (fn [[l r]] | |
(* (letter-val l) | |
(if (< (letter-val l) (letter-val r)) | |
-1 | |
1)))] | |
(->> roman-str | |
(partition 2 1 [\0]) | |
(map letter-tuple->dec) | |
(reduce + 0)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment