Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by dasich12
def checkio(data):
result=""
d = {1000: 'M' , 500: 'D', 100 : 'C', 50: 'L', 10: 'X', 5: 'V', 1: 'I'}
r = [("DCCCC","CM"),("CCCC","CD"),("LXXXX","XC"),("XXXX","XL"),("VIIII","IX"),("IIII","IV")]
for k,j in sorted(d.items(), reverse=True):
result = result+ "".join(j for i in range(0, data//k))
data-=(data//k)*k
for t in r:
result = result.replace(*t)
return result
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'
Sept. 15, 2015