Roman numerals/Encode: Difference between revisions
m
→{{header|Phix}}: use pygments, added cheat version
imported>Arakov |
m (→{{header|Phix}}: use pygments, added cheat version) |
||
(One intermediate revision by one other user not shown) | |||
Line 5,698:
=={{header|Phix}}==
<!--
with javascript_semantics
function toRoman(integer v)
sequence roman = {"M", "CM", "D","CD", "C","XC","L","XL","X","IX","V","IV","I"},
decml = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }
string res = ""
integer val = v
for i=1 to length(roman) do
while val>=decml[i] do
res &= roman[i]
val -= decml[i]
end while
end for
return {v,res} -- (for output)
end function
?apply({1990,2008,1666},toRoman)
▲<!--</syntaxhighlight>-->
</syntaxhighlight>
{{out}}
<pre>
{{1990,"MCMXC"},{2008,"MMVIII"},{1666,"MDCLXVI"}}
</pre>
=== cheating slightly ===
<syntaxhighlight lang="phix">
with javascript_semantics
requires("1.0.5")
function toRoman(integer n)
return {n,sprintf("%R",n)}
end function
</syntaxhighlight>
same output (builtins\VM\pprntfN.e/toRoman() is somewhat more obfuscated and faster than the above)
=={{header|Phixmonti}}==
Line 7,736 ⟶ 7,746:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="
[1000, "M"],
[900, "CM"],
|