Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Stretch-n-shrink solution in Clear category for Roman Numerals by Ilis
def checkio(data):
m = data
rome = ""
n, m = m // 1000, m % 1000
rome += "M" * n
n, m = m // 100, m % 100
rome += "C" * n
n, m = m // 10, m % 10
rome += "X" * n
n, m = m // 1, m % 1
rome += "I" * n
rome = rome.replace("IIIIIIIII", "IX")
rome = rome.replace("IIIII", "V")
rome = rome.replace("IIII", "IV")
rome = rome.replace("XXXXXXXXX", "XC")
rome = rome.replace("XXXXX", "L")
rome = rome.replace("XXXX", "XL")
rome = rome.replace("CCCCCCCCC", "CM")
rome = rome.replace("CCCCC", "D")
rome = rome.replace("CCCC", "CD")
return rome
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
# for i in range(1, 121):
# checkio(i)
# assert False, "stop it"
assert checkio(6) == 'VI', '6'
assert checkio(76) == 'LXXVI', '76'
assert checkio(499) == 'CDXCIX', '499'
assert checkio(3888) == 'MMMDCCCLXXXVIII', '3888'
print('Done! Go Check!')
April 1, 2019