Last active
January 20, 2024 12:03
-
-
Save herrfz/5aa88874fe7e4d2b6630a8fe751304f3 to your computer and use it in GitHub Desktop.
Convert to roman numeral
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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