Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second (pretend to be more universal than first) solution in Uncategorized category for Roman Numerals by arthur.fayzullin
def checkio(data):
units = [ 'M', 'C', 'X', 'I']
pentas = [ '' , 'D', 'L', 'V']
# 0 1 2 3 4 5 6 7 8 9
remainderToNumPreUnits = [ 0, 1, 2, 3, 1, 0, 0, 0, 0, 1, ]
remainderToNumPentas = [ 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, ]
remainderToNumPostUnits = [ 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, ]
remainderToNumNextUnits = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ]
reminders = list(map(int, str(data).zfill(len(units))))
return ''.join((map(lambda x: units[x] * remainderToNumPreUnits[reminders[x]] +
pentas[x] * remainderToNumPentas[reminders[x]] +
units[x] * remainderToNumPostUnits[reminders[x]] +
units[x - 1] * remainderToNumNextUnits[reminders[x]],
range(len(units)))))
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'
Sept. 9, 2016