Created
September 21, 2018 16:01
-
-
Save adamdavislee/6e051bbd252fdf01cd0289281013925f to your computer and use it in GitHub Desktop.
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
(with-test | |
(defn roman-numeral | |
[input] | |
(loop [input input, acc 0, ] | |
(if (empty? input) | |
acc | |
(let [convert {"I" 1, "V" 5, "X" 10, "L" 50, "C" 100, "D" 500, "M" 1000, } | |
curr-num (convert (subs input 0 1)) | |
op (if (and (not= 1 (count input)) | |
(< curr-num | |
(convert (subs input 1 2)))) | |
- +)] | |
(recur (subs input 1) | |
(op acc curr-num)))))) | |
(are | |
[a b] (= (roman-numeral a) b), | |
"XIV" 14, | |
"DCCCXXVII" 827, | |
"MMMCMXCIX" 3999, | |
"XLVIII" 48, )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment