from pathlib import Path from collections import Counter from math import gcd import json p=Path(__file__).resolve().parent;out=[] for line in (p/'actual-reference.txt').read_text().splitlines(): a=line.split();z,W,D,H=map(int,[a[1],a[3],a[5],a[7]]) if z>13:continue expected={int(k):int(v) for k,v in (s.split(':') for s in a[9:])} bits=[int(gcd(n*(n+2),W)==1) for n in range(W)] assert sum(bits)==D count=sum(bits[n%W] for n in range(1,H+1));hist=Counter() for start in range(W): hist[count]+=1 count-=bits[(start+1)%W];count+=bits[(start+H+1)%W] assert dict(hist)==expected out.append({'z':z,'W':W,'H':H,'all_integer_translates_match':True}) (p/'direct-check.json').write_text(json.dumps(out,indent=2)+'\n') print('PASS: direct gcd + sliding indicator matches all six z=7,11,13 histograms')