Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Roman Numerals solution in Uncategorized category for Roman Numerals by vvm70
def checkio(data):
r = (('I', 'X', 'C', 'M'), ('V', 'L', 'D', ''))
n = ''
for i, d in zip(range(len(str(data)))[::-1], str(data)):
if d in ('4', '9'):
n += r[0][i] + r[1-int(d)%4][i+int(d)%4]
else:
n += r[1][i] * (d not in ('0', '1', '2', '3')) + r[0][i] * (int(d) % 5)
return n
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'
print('Done! Go Check!')
June 21, 2020