import numpy as np, itertools, time cp=(0,0,1); p=3 def exposure_all(w,T): N=1<<(w-1); L=w+T+p+3 S=np.zeros((N,L),dtype=np.uint8) idx=np.arange(N) for j in range(w-1): S[:,j]=(idx>>j)&1 S[:,w-1]=1 e=np.zeros((N,T+p+1),dtype=np.uint8) for t in range(T+p+1): e[:,t]=S[:,0] mia=cp[t%p] new=np.empty_like(S) new[:,0]=S[:,1]^(S[:,0]|mia) new[:,1:L-1]=S[:,2:L]^(S[:,1:L-1]|S[:,0:L-2]); new[:,L-1]=0 S=new exp=np.full(N,-1) for t in range(T+1): if cp[t%p]==1: hit=(exp<0)&(e[:,t]!=e[:,t+p]); exp[hit]=t return exp,idx t0=time.time(); best={} for w in range(3,19): T=4*w+10; exp,idx=exposure_all(w,T) if (exp<0).any(): print(f"width {w}: {int((exp<0).sum())} starts not exposed by night {T}!"); mx=int(exp.max()); arg=idx[exp==mx] best[w]=(mx,set(int(a) for a in arg)) nest="" if w-1 in best: prev=best[w-1][1] # first w-1 lanterns of a width-w maximizer = bits 0..w-2 ; it is a width-(w-1) start only if bit w-2 is 1 ext=[a for a in best[w][1] if ((a & ((1<<(w-1))-1)) | (1<<(w-2)))==(a & ((1<<(w-1))-1)) and ((a & ((1<<(w-2))-1)) in {b & ((1<<(w-2))-1) for b in prev})] nest=f" extends a width-{w-1} longest survivor: {'YES' if ext else 'no'}" print(f"width {w:2d}: longest survivor exposed at night {mx:3d} ({mx/w:.2f} w), {len(arg)} such start(s){nest} [{time.time()-t0:.0f}s]",flush=True) if time.time()-t0>240: break