python3 <<'EOF' import math,random def Qm(a,b,m): q=[[0.0]*(m+1) for _ in range(m+1)] for k in range(m+1): for l in range(m+1): s=0.0 for i in range(max(0,l-m+k),min(k,l)+1): s=sum([s,math.comb(k,i)*(1-b)**i*b**(k-i)*math.comb(m-k,l-i)*a**(l-i)*(1-a)**(m-k-l+i)]) q[k][l]=s return q def cum(q): C=[] for k in range(len(q)): row=[] s=0.0 for j in range(len(q)): s=sum([s,q[k][j]]) row.append(s) C.append(row) return C def nxt(k,u,C): j=0 while C[k][j]=200: if cnt==0: cnt=10 hp=list(hb) hp[4]=(3,hp[4][1]) dp=db bb=db diff=0 for t in range(T): if mode==1 and t==4: hp[4]=(3,hp[4][1]) tb=(sum(sum(x) for x in hb)>=h) if W==5 else (sum(hb[4])>=h) tp=(sum(sum(x) for x in hp)>=h) if W==5 else (sum(hp[4])>=h) ab=0 ap=0 if bb>0: bb-=1 elif tb: bb=8 ab=1 if dp>0: dp-=1 elif tp: dp=8 ap=1 diff=sum([diff,ap-ab]) u1=random.random() u2=random.random() kt=nxt(hb[4][0],u1,C3) ko=nxt(hb[4][1],u2,C4) hb.insert(0,(kt,ko)) hb.pop() kt=nxt(hp[4][0],u1,C3) ko=nxt(hp[4][1],u2,C4) hp.insert(0,(kt,ko)) hp.pop() tot=sum([tot,diff]) cnts=sum([cnts,1]) else: cnt-=1 tb=(sum(sum(x) for x in hb)>=h) if W==5 else (sum(hb[4])>=h) if db>0: db-=1 elif tb: db=8 u1=random.random() u2=random.random() kt=nxt(hb[4][0],u1,C3) ko=nxt(hb[4][1],u2,C4) hb.insert(0,(kt,ko)) hb.pop() return tot/cnts,cnts print(resp(0.6,0.9,17,5,20000,50,0)) EOF