import numpy as np from collections import Counter from sawtooth import history rng=np.random.default_rng(79) for cp in ((0,0,1),(0,0,0,1),(0,1),(0,1,1),(0,1,1,1)): p=len(cp); idok=idtot=0; ok=chk=0; after=Counter(); where=Counter() for _ in range(20000): w=int(rng.integers(6,18)); s=rng.integers(0,2,size=w).astype(np.uint8); s[-1]=1 T=120; H=history(cp,s,T+p+2,depth=T+w+p+8); A=H[:T+2]; D=H[:T+1]^H[p:T+p+1] lit=[cp[t%p]==1 for t in range(T+2)] echo_death=next((t for t in range(T) if lit[t] and A[t,0]!=(1^cp[(t+1)%p])),T) for t in range(min(echo_death,T-1)-1): if (not lit[t]) and lit[t+1] and D[t,0]==1 and D[t,1]==1: E=int(A[t,0]==A[t,1]) idtot+=1; idok+=int(E==1^int(A[t+1,0])) chk+=1; ok+=int(E==cp[(t+2)%p]) nz1=np.nonzero(D[t+1])[0] if len(nz1): k=nz1[0]; after["transported" if D[t,k+1]==1 else "created"]+=1 where["at lantern 2" if k==1 else "deeper"]+=1 print(f"Mia {''.join(map(str,cp)):5s}: identity E=1+a1(t+1): {idok}/{idtot}; E=d(t+2) under the echo: {ok}/{chk}; new closest: {dict(after)} {dict(where)}")