Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,39 @@
|
|||
def decodeSingle(letter)
|
||||
if letter = "M"
|
||||
return 1000
|
||||
else if letter = "D"
|
||||
return 500
|
||||
else if letter = "C"
|
||||
return 100
|
||||
else if letter = "L"
|
||||
return 50
|
||||
else if letter = "X"
|
||||
return 10
|
||||
else if letter = "V"
|
||||
return 5
|
||||
else if letter = "I"
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
def decode(roman)
|
||||
result = 0
|
||||
uRoman = roman.toUpperCase()
|
||||
|
||||
for (i = 0) (i < len(uRoman) - 1) (i += 1)
|
||||
if decodeSingle(uRoman[i]) < decodeSingle(uRoman[i + 1])
|
||||
result -= decodeSingle(uRoman[i])
|
||||
else
|
||||
result += decodeSingle(uRoman[i])
|
||||
end
|
||||
end
|
||||
|
||||
result += decodeSingle(uRoman[len(uRoman) - 1])
|
||||
return result
|
||||
end
|
||||
|
||||
println decode("MCMXC")
|
||||
println decode("MMVIII")
|
||||
println decode("MDCLXVI")
|
||||
Loading…
Add table
Add a link
Reference in a new issue