Created
August 4, 2012 17:12
-
-
Save ulsa/3258811 to your computer and use it in GitHub Desktop.
Decimal to Roman Numeral converter, 2
This file contains hidden or 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
(let [ [fst snd] (filter odd? [1 2 3 4 5])] | |
(println fst snd)) | |
=> 1 3 |
This file contains hidden or 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
(filter #(>= 4 (first %)) mapping) | |
=> ([4 "IV"] [1 "I"]) |
This file contains hidden or 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
(let [ [ [n c] ] (filter ...)] | |
(recur ...)) |
This file contains hidden or 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
(filter #(>= i (first %)) mapping) |
This file contains hidden or 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 roman-numeral [i] | |
(loop [i i s ""] | |
...) |
This file contains hidden or 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
(recur (- i n) (str s c)) |
This file contains hidden or 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- roman-helper [i s] | |
(if (zero? i) | |
s | |
(let [[[n c]] (filter #(>= i (first %)) mapping)] | |
(roman-helper (- i n) (str s c))))) | |
(defn roman-numeral [i] | |
(roman-helper i "")) |
This file contains hidden or 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- roman-helper [i s] | |
(if (zero? i) | |
s | |
(let [[[n c]] (filter #(>= i (first %)) mapping)] | |
(recur (- i n) (str s c))))) | |
(defn roman-numeral [i] | |
(roman-helper i "")) |
This file contains hidden or 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 roman-numeral [i] | |
(let [roman-helper (fn [i s] | |
(if (zero? i) | |
s | |
(let [[[n c]] (filter #(>= i (first %)) mapping)] | |
(recur (- i n) (str s c)))))] | |
(roman-helper i ""))) |
This file contains hidden or 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 roman-numeral [i] | |
(loop [i i s ""] | |
(if (zero? i) | |
s | |
(let [[[n c]] (filter #(>= i (first %)) mapping)] | |
(recur (- i n) (str s c)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment