Skip to content

Instantly share code, notes, and snippets.

@pepasflo
Created Aug 2, 2018
Embed
What would you like to do?
(def table [
["M" 1000]
["D" 500]
["CD" 400]
["C" 100]
["L" 50]
["XL" 40]
["X" 10]
["IX" 9]
["V" 5]
["IV" 4]
["I" 1]])
(defn roman [i table]
(if (= i 0) "")
(if (= table []) "")
(def pair (first table))
(def symbl (first pair))
(def value (last pair))
(def quotient (unchecked-divide-int i value))
(def remainder (- i (* quotient value)))
(clojure.string/join (clojure.string/join (repeat quotient symbl)) (roman remainder (rest table))))
(roman 1 table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment