Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by m600
def checkio(data):
symbols = [("", "M"), ("D", "C"), ("L", "X"), ("V", "I")]
roman = []
x = 1000
y = 100
if data / x > 0:
roman.append("M"*(data / x))
for i in range (3):
if 0 < data % x / y < 4:
roman.append(symbols[i+1][1]*(data % x / y))
if data % x / y == 4:
roman.append(symbols[i+1][1] + symbols[i+1][0])
if data % x / y == 5:
roman.append(symbols[i+1][0])
if 5 < data % x / y < 9:
roman.append(symbols[i+1][0] + symbols[i+1][1]*(data % x / y - 5))
if data % x / y == 9:
roman.append(symbols[i+1][1] + symbols[i][1])
data %= x
x /= 10
y /= 10
return "".join(roman)
June 20, 2015