Skip to content

Instantly share code, notes, and snippets.

@david-hodgetts
Created April 11, 2013 21:52
Show Gist options
  • Save david-hodgetts/5367522 to your computer and use it in GitHub Desktop.
Save david-hodgetts/5367522 to your computer and use it in GitHub Desktop.
4Clojure problem 92 (Take Two)
(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