from collections import defaultdict from fractions import Fraction def run(load,read,check): C=load('C365_DATA.json')['cumulative_register'];ix=defaultdict(list) for i,z in enumerate(C):ix[z['coordinate']].append(i) pairs=load('C454_DATA.json')['K_pairs'];trials=[];hits=[] for A in [-2639,-2635]: for p in pairs: x,y=p['lower'],p['upper'];u,v=A-y,A-x;good=u in ix and v in ix row={'exchange_constant':A,'regular_pair':[x,y],'cumulative_pair':[u,v],'K_multiple':p['K_multiple'],'lower_regular_indices':p['lower_indices'],'upper_regular_indices':p['upper_indices'],'cumulative_indices':[ix.get(u,[]),ix.get(v,[])],'complete':good,'cross_span':x+y-A,'cross_span_K':str(Fraction(x+y-A,529)) if (x+y-A)%529 else (x+y-A)//529} check(f'preserved_gap_{A}_{x}_{y}',v-u==y-x) trials.append(row) if good:hits.append(row) return {'step':'C461','trials':trials,'complete_images':hits,'cumulative_register':C,'counts':{'trials':len(trials),'complete_images':len(hits),'by_exchange':{str(A):sum(h['exchange_constant']==A for h in hits) for A in [-2639,-2635]},'exact_17K_cross_spans':sum(h['cross_span']==17*529 for h in hits)},'scope':'Exactly the two inherited fixed exchanges and the48-record cumulative menu; no generated phase constant is added.'}