Created
November 22, 2010 14:29
-
-
Save benzen/710036 to your computer and use it in GitHub Desktop.
cesear kata
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
(defn convert [number] | |
"Convert a number between 50 and 0 to it's roman representation" | |
(defn convert-rec [acc num] | |
(cond (< num 4) | |
(concat acc (take num (repeat "i"))) | |
(= num 4) | |
(concat acc "iv") | |
(pos? (int (/ num 50))) | |
(cons acc "l") | |
(pos? (int (/ num 10))) | |
(do (let [ent (int (/ num 10)) ] | |
(cond (integer? (/ num 10)) | |
(concat acc (take ent (repeat "x"))) | |
:else | |
(convert-rec (cons acc (take ent(repeat "x"))) | |
(mod num 10))))) | |
(pos? (int (/ num 5))) | |
(do (let [ent (int (/ num 5))] | |
(cond (integer? (/ num 5)) | |
(concat acc (take ent(repeat "v"))) | |
:else | |
(convert-rec (concat acc (take ent (repeat "v"))) | |
(mod num 5))))))) | |
(apply str (flatten (convert-rec '() number)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment