14 lines
418 B
Text
14 lines
418 B
Text
with javascript_semantics
|
|
function romanDec(string s)
|
|
integer res = 0, prev = 0
|
|
for i=length(s) to 1 by -1 do
|
|
integer rdx = find(upper(s[i]),"IVXLCDM"),
|
|
rn = power(10,floor((rdx-1)/2))
|
|
if even(rdx) then rn *= 5 end if
|
|
res += iff(rn<prev?-rn:rn)
|
|
prev = rn
|
|
end for
|
|
return {s,res} -- (for output)
|
|
end function
|
|
|
|
?apply({"MCMXC","MMVIII","MDCLXVI"},romanDec)
|