Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
44
Task/Roman-numerals-Decode/Picat/roman-numerals-decode.picat
Normal file
44
Task/Roman-numerals-Decode/Picat/roman-numerals-decode.picat
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
go =>
|
||||
List = ["IV",
|
||||
"XLII",
|
||||
"M",
|
||||
"MCXI",
|
||||
"CMXI",
|
||||
"MCM",
|
||||
"MCMXC",
|
||||
"MMVIII",
|
||||
"MMIX",
|
||||
"MCDXLIV",
|
||||
"MDCLXVI",
|
||||
"MMXII"],
|
||||
foreach(R in List)
|
||||
printf("%-8s: %w\n", R, roman_decode(R))
|
||||
end,
|
||||
nl.
|
||||
|
||||
|
||||
roman_decode(Str) = Res =>
|
||||
if Str == "" then
|
||||
Res := ""
|
||||
else
|
||||
D = new_map(findall((R=D), roman(R,D))),
|
||||
Res = 0,
|
||||
Old = 0,
|
||||
foreach(S in Str)
|
||||
N = D.get(S),
|
||||
% Fix for the Roman convention that XC = 90, not 110.
|
||||
if Old > 0, N > Old then
|
||||
Res := Res - 2*Old
|
||||
end,
|
||||
Res := Res + N,
|
||||
Old := N
|
||||
end
|
||||
end.
|
||||
|
||||
roman('I', 1).
|
||||
roman('V', 5).
|
||||
roman('X', 10).
|
||||
roman('L', 50).
|
||||
roman('C', 100).
|
||||
roman('D', 500).
|
||||
roman('M', 1000).
|
||||
Loading…
Add table
Add a link
Reference in a new issue