Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by jacekgrycza
def checkio(data):
x=['I','V','X','L','C','D','M']
y=['a' for i in range(0,100)]
k=0
p=0
r=0
q=1000
for i in range(0,4):
p=r
k=data//q
k=int(k)
if (k>=0 and k<4):
for j in range(p,p+k):
y[j]=x[6-2*i]
r=r+1
if (k>=5 and k<9):
y[p]=x[6-2*i+1]
p=p+1
r=r+1
for j in range(p, p+k-5):
y[j]=x[6-2*i]
r=r+1
if k==4:
y[p]=x[6-2*i]
y[p+1]=x[6-2*i+1]
p=p+2
r=r+2
if k==9:
y[p]=x[6-2*i]
y[p+1]=x[6-2*i+2]
p=p+2
r=r+2
data=data%q
q=q/10
l=p
t=0
for i in range(0,50):
if(y[i]!='a'):
t=t+1
else:
break
n=[y[i] for i in range(0,t)]
z=''.join(n)
return(z)
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'
Oct. 17, 2016