Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
#comments, per digit str multiplication solution in Clear category for Roman Numerals by mlb00
def checkio(data): # deconstruct by digit, return numeral for 0 < data < 4000
n, m, c, x, i = '', data/1000, (data % 1000)/100, \
(data % 100)/10, (data % 10)
if m > 0: # thousands digit 0-3
n += 'M' * m
if c < 5: # hundreds digit 0-4
n += 'CD' if c == 4 else 'C' * c
elif c > 4: # hundreds digit 5-9
n += 'CM' if c == 9 else 'D' + 'C' * (c-5)
if x < 5: # tens digit 0-4
n += 'XL' if x == 4 else 'X' * x
elif x > 4: # tens digit 5-9
n += 'XC' if x == 9 else 'L' + 'X' * (x-5)
if i < 5: # ones digit 0-4
n += 'IV' if i == 4 else 'I' * i
elif i > 4: # ones digit 5-9
n += 'IX' if i == 9 else 'V' + 'I' * (i-5)
return n
March 29, 2015
Comments: