Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Roman Numerals by fridgeir
# migrated from python 2.7
INTS = [1,4,5,9,10,40,50,90,100,400,500,900,1000]
ROME = ["I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"]
def checkio(data):
number = data
result =""
i = len(INTS) - 1
while(number >0):
while number >= INTS[i]:
print("num:",number)
number -= INTS[i]
result += ROME[i]
i -= 1
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'
July 6, 2014