21 lines
588 B
Text
21 lines
588 B
Text
go =>
|
|
List = [455,999,1990,1999,2000,2001,2008,2009,2010,2011,2012,1666,3456,3888,4000],
|
|
foreach(Val in List)
|
|
printf("%4d: %w\n", Val, roman_encode(Val))
|
|
end,
|
|
nl.
|
|
|
|
roman_encode(Val) = Res =>
|
|
if Val <= 0 then
|
|
Res := -1
|
|
else
|
|
Arabic = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],
|
|
Roman = ["M", "CM", "D", "CD", "C", "XC","L","XL","X","IX","V","IV","I"],
|
|
Res = "",
|
|
foreach(I in 1..Arabic.length)
|
|
while(Val >= Arabic[I])
|
|
Res := Res ++ Roman[I],
|
|
Val := Val - Arabic[I]
|
|
end
|
|
end
|
|
end.
|