Created
January 27, 2025 10:07
-
-
Save ludndev/81ef0afa7ab0970828dcb877624ab8a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def int_to_roman(num: int) -> str: | |
ones = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"] | |
tens = ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"] | |
hrns = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"] | |
ths = ["", "M", "MM", "MMM"] | |
return ths[num // 1000] + hrns[(num % 1000) // 100] + tens[(num % 100) // 10] + ones[num % 10] | |
print(int_to_roman(3)) # Output: "III" | |
print(int_to_roman(58)) # Output: "LVIII" | |
print(int_to_roman(1994)) # Output: "MCMXCIV" | |
print(int_to_roman(2025)) # Output: "MMXXV" | |
print(int_to_roman(3999)) # Output: "MMMCMXCIX" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment