Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by bmu0
def checkio(data):
return (
data // 1000 * "M"
+ (data % 1000 // 100 == 1) * "C"
+ (data % 1000 // 100 == 2) * "CC"
+ (data % 1000 // 100 == 3) * "CCC"
+ (data % 1000 // 100 == 4) * "CD"
+ (data % 1000 // 100 == 5) * "D"
+ (data % 1000 // 100 == 6) * "DC"
+ (data % 1000 // 100 == 7) * "DCC"
+ (data % 1000 // 100 == 8) * "DCCC"
+ (data % 1000 // 100 == 9) * "CM"
+ (data % 100 // 10 == 1) * "X"
+ (data % 100 // 10 == 2) * "XX"
+ (data % 100 // 10 == 3) * "XXX"
+ (data % 100 // 10 == 4) * "XL"
+ (data % 100 // 10 == 5) * "L"
+ (data % 100 // 10 == 6) * "LX"
+ (data % 100 // 10 == 7) * "LXX"
+ (data % 100 // 10 == 8) * "LXXX"
+ (data % 100 // 10 == 9) * "XC"
+ (data % 10 == 1) * "I"
+ (data % 10 == 2) * "II"
+ (data % 10 == 3) * "III"
+ (data % 10 == 4) * "IV"
+ (data % 10 == 5) * "V"
+ (data % 10 == 6) * "VI"
+ (data % 10 == 7) * "VII"
+ (data % 10 == 8) * "VIII"
+ (data % 10 == 9) * "IX"
)
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'
print('Done! Go Check!')
Jan. 8, 2022
Comments: