Skip to content

Instantly share code, notes, and snippets.

@herrfz
Last active January 20, 2024 12:03
Show Gist options
  • Save herrfz/5aa88874fe7e4d2b6630a8fe751304f3 to your computer and use it in GitHub Desktop.
Save herrfz/5aa88874fe7e4d2b6630a8fe751304f3 to your computer and use it in GitHub Desktop.
Convert to roman numeral
from itertools import repeat
def to_roman(n):
return (''.join(repeat('I', n))
.replace('IIIII', 'V')
.replace('VV', 'X')
.replace('XXXXX', 'L')
.replace('LL', 'C')
.replace('CCCCC', 'D')
.replace('DD', 'M')
.replace('VIIII', 'IX')
.replace('IIII', 'IV')
.replace('LXXXX', 'XC')
.replace('XXXX', 'XL')
.replace('DCCCC', 'CM')
.replace('CCCC', 'CD'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment