Roman Numerals Conversion
Kay C Lan
lan.kc.macmail at gmail.com
Fri Mar 26 03:10:08 EDT 2010
Here's my version
function rom2Ara theNumber
constant i=1,v=5,x=10,l=50,c=100,d=500,m=1000
put 0 into tTotal
put 1000 into tLastChar
repeat for each char tChar in theNumber
put value(tChar) into tNum -- how unfortunate
if (tNum > tLastChar) then
subtract (2*tLastChar) from tTotal
end if
add tNum to tTotal
put tNum into tLastChar
end repeat
return tTotal
end rom2Ara
I had hoped for a Rev miracle in that the put value() step wasn't going to
be required. I was hoping as Rev pulled out each char it would see that it
was a constant and automatically convert it. Oh well ;-)
This code is slightly slower than Marks
romanToArab = 329 ms for 10000 repeats. (Marks)
rom2Ara = 381 ms for 10000 repeats. (Mine)
More information about the use-livecode
mailing list