from pathlib import Path GAPS=(1,2,3,4,6,8,12,16,24,32,48,64) N=192 R=4 counts={q:[0,0] for q in GAPS} prev={0:(0,0,0),1:(1,0,0)} shorter=[set(),set(prev)] for n in range(2,N+1): mask=(1<<(n-1))-1 cur={} for high,(evens,odds,flags) in prev.items(): shifted=(0,2,1)[flags] for bit in (0,1): w=2*high+bit low=prev.get(w&mask) if low is None:continue orientation=shifted|low[2] if n%4==3: middle=(w>>(n//2))&1 if bit!=middle or w>>(n-1)!=middle:orientation|=2 if middle else 1 even,odd=2*odds+bit,evens if orientation!=3 and even in shorter[(n+1)//2] and odd in shorter[n//2]:cur[w]=(even,odd,orientation) for q in GAPS: starts=(1<>q))&starts).bit_count()+2*R*((w^(w>>(2*q)))&starts2).bit_count() for w in cur)) if n<=N//2:shorter.append(set(cur)) prev=cur if n%32==0:print(n,len(cur),flush=True) Path(__file__).with_name('complete_rows_joint_doubling.txt').write_text('\n'.join(' '.join(map(str,[n]+[counts[q][n] for q in GAPS])) for n in range(N+1))+'\n')