Skip to content

Instantly share code, notes, and snippets.

@d11wtq d11wtq/roman.clj
Last active Aug 29, 2015

What would you like to do?
Roman numerals
(ns roman.core)
(defmacro defpairs
"Helper macro to make ordered defs for pairs nicer."
[varname pairs]
`(def ~varname
(partition 2 ~pairs)))
(defpairs digits
["M" 1000
"D" 500
"C" 100
"L" 50
"X" 10
"V" 5
"I" 1])
(defn numerals
"Convert integer n to roman numerals."
(loop [n n, acc ""]
(if (zero? n)
(let [[s v] (some #(if (<= (second %) n) %)
(recur (- n v) (str acc s))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.