Last active
December 15, 2015 09:39
-
-
Save j1n3l0/5239956 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
(fn [n] | |
(when (and (< n 4000) (> n 0)) | |
(loop [n n | |
m {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"} | |
[f & d] (reverse (sort (keys m))) | |
r []] | |
(if (zero? n) | |
(apply str (flatten r)) | |
(recur (mod n f) m d (conj r (repeat (unchecked-divide-int n f) (m f)))))))) |
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
(fn __ | |
([coll] | |
(let [coll (map {\I 1 \V 5 \X 10 \L 50 \C 100 \D 500 \M 1000} coll)] | |
(__ coll 0))) | |
([coll acc] | |
(if-not (seq coll) | |
acc | |
(let [a (first coll) | |
b (second coll) | |
f (if (and a b (< a b)) - +)] | |
(__ (rest coll) (f acc a)))))) |
And this is the reverse: Roman to Arabic
converter :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After several iterations, a version of
Integer to Roman Numerals
I'm somewhat happy with :)