This program has been disqualified.
Author | tzoides |
Submission date | 2016-08-07 01:25:14.061941 |
Rating | 5357 |
Matches played | 3 |
Win rate | 66.67 |
import random
k2i={'R':0,'P':1,'S':2}
i2k={0:'R',1:'P',2:'S'}
def mdl(N):
N%=3
if N<0:
N+=3
return N
if not input:
mRNA=""
tRNA=""
flag=[False]*2
subs=[[0]*6]*2
prin=[[[0]*6]*2]*4
meta=[0]*4
output=random.choice("RPS")
else:
for i in range(4):
x=0
y=0
for j in range(2):
for k in range(6):
if prin[i][j][k]>prin[i][x][y]:
x=j
y=k
if flag[x]:
y=mdl(subs[x][y]-k2i[input])
if y==2:
meta[i]-=1
else:
meta[i]+=y
for j in range(2):
if flag[j]:
for k in range(6):
prin[1][j][k]*=0.9
prin[3][j][k]*=0.9
y=mdl(subs[j][k]-k2i[input])
if y==0:
for i in range(2,4):
prin[i][j][k]-=0.1
elif y==1:
for i in range(4):
prin[i][j][k]+=1
elif y==2:
for i in range(4):
if i<2 or prin[i][j][k]<2:
prin[i][j][k]-=1
else:
prin[i][j][k]*=0.5
tRNA+=input
mRNA+=output
output=random.choice("RPS")
i=min(36,len(tRNA))
j=-1
while i>1 and j<0:
i-=1
RNA=tRNA[-i:]
j=tRNA.rfind(RNA,0,-1)
flag[0]=(j>=0)
if flag[0]:
for k in range(3):
subs[0][k]=mdl(k2i[tRNA[i+j]]-k+1)
for k in range(3):
subs[1][k+3]=mdl(k2i[mRNA[i+j]]-k-1)
i=min(36,len(mRNA))
j=-1
while i>1 and j<0:
i-=1
RNA=mRNA[-i:]
j=mRNA.rfind(RNA,0,-1)
flag[0]=flag[0] and (j>=0)
flag[1]=flag[0]
if flag[1]:
for k in range(3):
subs[1][k]=mdl(k2i[tRNA[i+j]]-k+1)
for k in range(3):
subs[0][k+3]=mdl(k2i[mRNA[i+j]]-k-1)
i=meta.index(max(meta))
if meta[i]>0:
x=0
y=0
for j in range(2):
for k in range(6):
if prin[i][j][k]>prin[i][x][y]:
x=j
y=k
if flag[x] and prin[i][x][y]>0:
output=i2k[subs[x][y]]