Roman numerals/Encode: Difference between revisions
m
→{{header|Phix}}: use pygments, added cheat version
m (→{{header|Phix}}: use pygments, added cheat version) |
|||
(4 intermediate revisions by 3 users not shown) | |||
Line 3,130:
<syntaxhighlight lang="text">
values[] = [ 1000 900 500 400 100 90 50 40 10 9 5 4 1 ]
symbol$[] = [ "M" "CM" "D" "CD" "C" "XC" "L" "XL" "X" "IX" "V" "IV" "I" ]
rom$ = ""▼
for i = 1 to len values[]
while dec >= values[i]
Line 3,140 ⟶ 3,139:
.
.
return rom$
.
print
</syntaxhighlight>
Line 3,261 ⟶ 3,258:
=={{header|Elena}}==
{{trans|C#}}
ELENA
<syntaxhighlight lang="elena">import system'collections;
import system'routines;
Line 3,284 ⟶ 3,281:
extension op
{
}
Line 5,701 ⟶ 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 }
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,739 ⟶ 7,746:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="
[1000, "M"],
[900, "CM"],
|