Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Roman Numerals by Alejen
def checkio(d):
f = lambda n,i,v,x:["",i,2*i,3*i,i+v,v,v+i,v+2*i,v+3*i,i+x][int(n)]
[a,b,c,d]='{:0>4}'.format(str(d))
return f(a,'M','','')+f(b,'C','D','M')+f(c,'X','L','C')+f(d,'I','V','X')
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'
June 29, 2015