Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Kristof
def roman(n):
r0 = [ "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X" ]
r1 = [ "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "C" ]
r2 = [ "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "M" ]
if n <= 10:
return r0[n]
elif n <= 100:
return r1[n // 10] + roman(n % 10)
elif n <= 1000:
return r2[n // 100] + roman(n % 100)
else:
return "M" * (n // 1000) + roman(n % 1000)
checkio = roman
Dec. 6, 2015