|
In my opinion, that script, as is, will never say a good translation between numbers and romans ones. In the way you wrote it, the program, does what you write, it sees a 4 and it uses the I cause you didn't made it understand the exceptions, like IV, cause, it says: if you see a 5, write V, but, even the 4 needs the V.
I'm starting with Ruby so I can't give you a code answer yet, but this is my hint: Split the number starting from the big to small like:
3102 is divisible for 1000? get the integer of that and go on taking off the 3 from the number 102 is divisible for 500? no, so go for the 100. How many? 1 and take it off. 2 is divisible for 5 go for the 1.
In this way is a more checked way to do it. not perfect, but better.
Another hint to make it accettable, make it check the numbers 4, and 9 to make it IV IX and test it again.
|