Created
April 11, 2013 21:52
-
-
Save david-hodgetts/5367522 to your computer and use it in GitHub Desktop.
4Clojure problem 92 (Take Two)
This file contains hidden or 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 | |
([s] (roman (seq s) 0)) | |
([s v] | |
(let [ | |
rdigits {\M 1000, \D 500, \C 100, \L 50, \X 10, \V 5, \I 1} | |
sdigits {"IV" 4, "IX" 9, "XL" 40, "XC" 90, "CD" 400, "CM" 900} | |
c1 (first s) | |
c12 (str c1 (second s)) | |
v1 (get rdigits c1 0) | |
v12 (get sdigits c12)] | |
(if (empty? s) v | |
(if (nil? v12) | |
(roman (rest s) (+ v v1)) | |
(roman (drop 2 s) (+ v v12)) | |
) | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment