Skip to content

@j1n3l0 /gist:5239956
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
(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))))))))
(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))))))
@j1n3l0
Owner

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

@j1n3l0
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.