Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
My First Head-Bursting Decision solution in Creative category for Reverse Roman Numerals by d_rabenko
from operator import add
from functools import reduce
from itertools import zip_longest
def reverse_roman(roman_string):
#replace this for solution
d = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
if roman_string:
return reduce(add, ((-d[x], d[x])[y is None or d[x] >= d[y]] for x, y in
zip_longest(roman_string, roman_string[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!');
Oct. 7, 2017
Comments: