Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
A pair of tuples solution in Clear category for Reverse Roman Numerals by quarkov
def reverse_roman(text):
roman = ('M', 'D', 'C', 'L', 'X', 'V', 'I', '')
arab = (1000, 500, 100, 50, 10, 5, 1)
result = 0
for i in range(len(text)-1):
now = roman.index(text[i])
following = roman.index(text[i+1])
if now > following:
result -= arab[now]
else:
result += arab[now]
result += arab[roman.index(text[-1])]
return result
May 18, 2018
Comments: