Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
All the Romans (there are no romans left) solution in Speedy category for Roman Numerals by oduvan
ROMANS = (('M',1000),('CM',900),('D',500),('CD',400),('C',100),('XC',90),('L',50),('XL',40),('X', 10),('IX',9),('V',5),('IV', 4),('I',1))
def dec_to_rom(number):
result = ''
while number:
for (roman, value) in ROMANS:
if number >= value:
number -= value
result += roman
break
return result
def gen_roms(amount):
line = "''"
for num in range(1, amount):
line += ",'" + dec_to_rom(num) + "'"
gg = {}
exec('r = (' + line + ')', gg)
return gg['r']
ALL_ROM = gen_roms(5000)
checkio=lambda x:ALL_ROM[x]
Sept. 12, 2016
Comments: