"""Independent phase intersections, small true tiles and screening edge cases.""" import importlib.util,itertools,json,math,pathlib,hashlib,collections p=pathlib.Path(__file__).parent;source=p/'job1406-screen.py' assert hashlib.sha256(source.read_bytes()).hexdigest()=='45e1a5dbec1a226b35709089ac30298587243becf4afaae8a532d513b9bd82cf' sp=importlib.util.spec_from_file_location('author',source);a=importlib.util.module_from_spec(sp);sp.loader.exec_module(a) def primes(n):return [q for q in range(2,n+1) if all(q%d for d in range(2,math.isqrt(q)+1))] def direct_gaps(g,q): best=1 for i in range(len(g)): phase={0,2};y=0;n=1 for j in range(2*len(g)): y+=g[(i+j)%len(g)];phase &= {y%q,(y+2)%q} if not phase:break n+=1 else:raise AssertionError('test requires a barrier') best=max(best,n) return best small=[] for x in [5,7,11,13]: P=math.prod(primes(x));R=[r for r in range(P) if math.gcd(r*(r+2),P)==1] original,M,_=a.build_tile(x);assert original==R and M==P gaps=[R[0]+P-R[-1]]+[b-c for c,b in zip(R,R[1:])] assert 6 in gaps and sum(gaps)==P qs=[q for q in primes(59) if q>x] row={q:direct_gaps(gaps,q) for q in qs};assert row==a.row_by_automaton(gaps,qs) small.append({'level':x,'period':P,'slots':len(R),'row':row}) for prefix in itertools.product([7,2,5,6],repeat=4): g=list(prefix)+[6];assert a.row_by_automaton(g,[7])[7]==direct_gaps(g,7) toy=[7,7,7,2,6] assert a.row_by_automaton(toy,[7])[7]==5 and a.multiset_screen(toy,[7])[7] long=[7]*9+[6] assert direct_gaps(long,7)==10 and a.row_by_definition(long,[7])[7]==9 res,M,_=a.build_tile(5);g=list(a.gaps_of(res,M)) assert direct_gaps(g,7)==2 and a.multiset_screen(g,[7],need=2)[7] custody=p/'input1071.json';assert hashlib.sha256(custody.read_bytes()).hexdigest()=='daa5d6d095b5986b65e7a4ac501b2fe3a9c572d5f7fc94bcd2e255e63d2ea892' lv=next(l for l in json.loads(custody.read_text())['levels'] if l['x']==23);counts={int(k):v for k,v in lv['full_gap_counts'].items()} qrow=[q for q in primes(199) if q>23];survive=[] for q in qrow: z=sum(c for g,c in counts.items() if g%q==0);plus=sum(c for g,c in counts.items() if g%q==2);minus=sum(c for g,c in counts.items() if g%q==q-2) max_inventory_chain=z+2*min(plus,minus)+int(plus!=minus) if max_inventory_chain>=4:survive.append(q) assert survive==[29,31,37,41,43,47] # Bounded independent local witness for the lone length3 row, no whole T23 reconstruction. P23=223092870;R=[r for r in range(1000000) if math.gcd(r*(r+2),P23)==1];w=None for i in range(len(R)-2): phases={R[i]%31,(R[i]+2)%31} for v in R[i+1:i+3]:phases &= {v%31,(v+2)%31} if phases:w={'positions':R[i:i+3],'phase_a':min(phases)};break out={'passed':True,'small_true_tiles':small,'toy_automaton_cases':256,'generic_inventory_false_negative':{'gaps':toy,'p':7,'true_L':5,'author_rules_out':True,'scope':'Generic gap list, not asserted to be a twin-admissible tile'},'literal_cap_control':{'gaps':long,'p':7,'true_L':10,'author_definition':9},'configurable_need_counterexample':{'tile':5,'p':7,'need':2,'actual_L':2,'author_rules_out':True},'T23_correct_inventory_survivors':survive,'T23_local_length3_witness':w,'large_row_scope':'Not an independent full T23 row rerun'} (p/'spot-results.json').write_text(json.dumps(out,indent=2),encoding='utf-8');print(json.dumps({'passed':True,'local_witness':w}))