-
-
Save pepasflo/913c7d7c109f74d2e72e2d1f734f4735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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