Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by DanyC97
def checkio(data):
base = "I" * data
rs = (("I" * 5, "V"),
("V" * 2, "X"),
("X" * 5, "L"),
("L" * 2, "C"),
("C" * 5, "D"),
("D" * 2, "M"),
("DCCCC", "CM"),
("CCCC", "CD"),
("LXXXX", "XC"),
("XXXX", "XL"),
("VIIII", "IX"),
("IIII", "IV"))
for r in rs:
base = base.replace(*r)
return base
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(6) == 'VI', '6'
assert checkio(76) == 'LXXVI', '76'
assert checkio(499) == 'CDXCIX', '499'
assert checkio(3888) == 'MMMDCCCLXXXVIII', '3888'
#checkio(7)
Oct. 30, 2016
Comments: