Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2011 06:41
Show Gist options
  • Save anonymous/1446300 to your computer and use it in GitHub Desktop.
Save anonymous/1446300 to your computer and use it in GitHub Desktop.
;; flengyel's solution to Write Roman Numerals
;; https://4clojure.com/problem/104
(fn [n]
(let [rmap {1000 "M",900 "CM",500 "D",400 "CD", 100 "C", 90 "XC", 50 "L", 40 "XL", 10 "X", 9 "IX", 5 "V", 4 "IV", 1 "I"}]
(first (reduce
(fn [[s n] e]
(loop [s s n n]
(if (< n e)
[s n]
(recur (str s (rmap e)) (- n e)))))
["" n] (reverse (sort (keys rmap)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment