Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Roman Numerals by UFO665
# migrated from python 2.7
dct = {1: {"val": "I", "cmpVal": 0},
5: {"val": "V", "cmpVal": 1},
10: {"val": "X", "cmpVal": 1},
50: {"val": "L", "cmpVal": 10},
100: {"val": "C", "cmpVal": 10},
500: {"val": "D", "cmpVal": 100},
1000: {"val": "M", "cmpVal": 100}}
def checkio(data):
res = ""
while data > 0:
for k, v in sorted(iter(dct.items()), reverse=True):
if k - v["cmpVal"] <= data < k and 0 < k - data <= v["cmpVal"]:
res += "{}{}".format(dct[v["cmpVal"]]["val"], v["val"])
data -= k - v["cmpVal"]
break
elif data >= k:
res += v["val"]
data -= k
break
return res
Dec. 9, 2015