Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by kurnic
def checkio(data):
result = ""
tens = ["I","X","C","M",""]
fives = ["V","L","D",""]
for i in range(4):
n = data%10
if n < 4: result = tens[i]*n + result
elif n < 5: result = tens[i] + fives[i] + result
elif n < 9: result = fives[i] + tens[i]*(n-5) + result
else: result = tens[i] + tens[i+1] + result
data /= 10
return result
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'
Dec. 3, 2015