Roman numerals/Decode: Difference between revisions
m
→{{header|Phix}}: use pygments, added cheat version
Not a robot (talk | contribs) (Add Refal) |
m (→{{header|Phix}}: use pygments, added cheat version) |
||
Line 5,329:
=={{header|Phix}}==
<!--
<syntaxhighlight lang="phix">
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)
{{out}}
<pre>
{{"MCMXC",1990},{"MMVIII",2008},{"MDCLXVI",1666}}
</pre>
=== cheating slightly ===
<syntaxhighlight lang="phix">
with javascript_semantics
requires("1.0.5")
function romanDec(string s)
return {s,scanf(s,"%R")[1][1]}
end function
</syntaxhighlight>
same output, if applied the same way as above, error handling omitted
=={{header|Phixmonti}}==
|