Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by grillo
def checkio(data):
def roman(num,c1,c2,c3):
if num <= 3:
return c1*num
elif num <= 5:
return c1*(5-num) + c2
elif num <= 8:
return c2 + c1*(num-5)
else:
return c1*(10-num) + c3
#replace this for solution
return roman(data//1000,'M','a','b') + roman((data//100) % 10,'C','D','M') + roman((data//10)%10,'X','L','C') + roman(data%10,'I','V','X')
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'
Jan. 14, 2015