Skip to content

Instantly share code, notes, and snippets.

@pepasflo
Created August 2, 2018 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepasflo/913c7d7c109f74d2e72e2d1f734f4735 to your computer and use it in GitHub Desktop.
Save pepasflo/913c7d7c109f74d2e72e2d1f734f4735 to your computer and use it in GitHub Desktop.
(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