Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
LAZY solution in Clear category for Roman Numerals by timiway
FIRST_TEN = ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]
FIRST_CEN = ["X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"]
FIRST_MIL = ["C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"]
def checkio(data):
NBR = ""
mil = (data-(data%1000))//1000
data-=mil*1000
for i in range(mil):
NBR += "M"
mil = (data%1000- data%100)//100
if mil:
NBR+=FIRST_MIL[mil-1]
dec = (data%100- data%10)//10
if dec:
NBR+=FIRST_CEN[dec-1]
uni = data%10
if uni:
NBR+=FIRST_TEN[uni-1]
return NBR
#These "asserts" using only for self-checking and not necessary for auto-testing
May 13, 2014