Actually - the original version doesn't work:
user= (to-roman 7)
III
Is not quite right...
Whereas your version gives the correct output:
user= (roman-numeral 7)
VII
Your version is very clear. It is not necessary to check if the
remaining value is greater than any of the previously found
And also from that site the Haskell version is pretty neat though
somewhat esoteric!
(defn digit [x y z k]
(condp = k
1 [x]
2 [x x]
3 [x x x]
4 [x y]
5 [y]
6 [y x]
7 [y x x]
8 [y x x x]
9 [x z]))
(defn tim-roman
[n]
(cond
(= n 0)
(= n 1000) (cons
On Dec 25, 2009, at 6:13 PM, Piotr 'Qertoip' Włodarek wrote:
What is the most clear and idiomatic way to convert arabic numbers to roman
notation?
Though it may miss the true goal of the exercise, there's also this option:
user= (clojure.contrib.pprint/cl-format nil ~...@r 3991
On Dec 26, 3:46 am, Mark Engelberg mark.engelb...@gmail.com wrote:
I reworked your example in a way that I believe to be more clear.
I'll leave it to other readers to judge:
This is awesome, thank you.
--
You received this message because you are subscribed to the Google
Groups Clojure group.
What is the most clear and idiomatic way to convert arabic numbers to
roman notation? My take:
(def roman
(hash-map
1 I,
4 IV,
5 V,
9 IX,
10 X,
40 XL,
50 L,
90 XC,
100 C,
400 CD,
500 D,
900 CM,
1000 M
)
)
(defn to-roman
([n]
(to-roman
Structurally, I'd say your program is just fine. But, it did take me
a while to convince myself that your program worked, and understand
why, so I'd say it is less clear than it could be.
When striving for clarity, it is essential to:
1. Break your program into small, easily understandable