[GOODIE][ENH] Roman Numerals
Stefan Matthias Aust
sma at 3plus4.de
Sun May 21 15:22:01 UTC 2000
At 00:37 21.05.00 +0200, Andreas Kuckartz wrote:
>BTW: This is my first Change Set sent to this list. Let me know if something
>is wrong or could be improved.
Everything is fine. You even correctly used an attachement. This is
something other Squeakers seem still to have problems with or simply don't
want to use.
So it was easy to study your code. Inspired by your idea, I completely
rewrote and renamed it (sorry ;-) and also added a method to parse strings
as roman numbers.
Any chance to get this shorter?
romanNumber
| value v1 v2 |
value _ v1 _ v2 _ 0.
self reverseDo:
[:each |
v1 _ #(1 5 10 50 100 500 1000) at: ('IVXLCDM' indexOf: each).
v1 >= v2
ifTrue: [value _ value + v1]
ifFalse: [value _ value - v1].
v2 _ v1].
^ value
BTW, what's up with numbers >= 5000? "100000 romanString" works like a
charm, emitting 1000 'M's, and can correctly converted back, but, well,
it's not the sort of number, I'd expect ;-) Did our Roman friends never
deal with larger numbers?
bye
More information about the Squeak-dev
mailing list
|