Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:5239956
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
(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))))))))
View gist:5239956
1 2 3 4 5 6 7 8 9 10 11
(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))))))
Owner

After several iterations, a version of Integer to Roman Numerals I'm somewhat happy with :)

Owner

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
Something went wrong with that request. Please try again.