Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Reverse Roman Numerals by oLeBeLo
ROM = {"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
def reverse_roman(roman):
val = list(map(lambda c:ROM[c],roman))
real_val = [v if v>=val[i+1] else -v for i,v in enumerate(val[:-1])]
return sum(real_val)+val[-1]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert reverse_roman('VI') == 6, '6'
assert reverse_roman('LXXVI') == 76, '76'
assert reverse_roman('CDXCIX') == 499, '499'
assert reverse_roman('MMMDCCCLXXXVIII') == 3888, '3888'
print('Great! It is time to Check your code!');
Nov. 21, 2019