Skip to content

Instantly share code, notes, and snippets.

@shinokada
Created May 24, 2014 06:06
Show Gist options
  • Save shinokada/52956956d6cf5187af76 to your computer and use it in GitHub Desktop.
Save shinokada/52956956d6cf5187af76 to your computer and use it in GitHub Desktop.
@data = [
["M" , 1000],
["CM" , 900],
["D" , 500],
["CD" , 400],
["C" , 100],
["XC" , 90],
["L" , 50],
["XL" , 40],
["X" , 10],
["IX" , 9],
["V" , 5],
["IV" , 4],
["I" , 1]
]
# ...
def toArabic(rom)
reply = 0
for key, value in @data
while rom.index(key) == 0
reply += value
rom.slice!(key)
end
end
reply
end
p toArabic("CDXCIX")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment