Created
March 1, 2012 05:42
-
-
Save anonymous/1947594 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
;; ariarule's solution to Write Roman Numerals | |
;; https://4clojure.com/problem/104 | |
(fn to-roman [n] | |
(let [sep-rom (take-last 4 (map #(Integer/parseInt (str %)) (str "000" n))) | |
rom-m (first sep-rom) | |
rom-less (rest sep-rom)] | |
(apply str | |
(concat (repeat rom-m \M) | |
(mapcat | |
#(cond | |
(<= %1 3) (repeat %1 %2) | |
(= %1 4) (list %2 (:v %3)) | |
(<= %1 8) (concat (list (:v %3)) (repeat (- %1 5) %2)) | |
:9 (list %2 (:x %3))) | |
rom-less | |
'(\C \X \I) | |
'({:v \D :x \M} | |
{:v \L :x \C} | |
{:v \V :x \X})))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment