from collections import defaultdict,Counter def run(load,read,check): r=load('C286_DATA.json')['target_register'];ix=defaultdict(list) for i,z in enumerate(r):ix[z['center']].append(i) pairs=[];labels=[];residual=defaultdict(list);keys=['gear','Cainan','Terah60','full430'] for x in sorted(ix): y=x+1250 if y not in ix:continue pairs.append({'lower':x,'upper':y,'lower_indices':ix[x],'upper_indices':ix[y]}) for i in ix[x]: for j in ix[y]: a,b=r[i],r[j];same=all(a[k]==b[k] for k in keys);family=None if a['tradition']=='MT' and a['role']=='Shem death' and b['tradition'] in ['SP','LXX'] and b['role']=='Shem birth' and b.get('rail') in [None,'primary'] and same:family='A_matched_Shem' elif a['tradition']=='MT' and a['role']=='Flood close' and b['tradition']=='SP' and b['role']=='Noah birth' and b.get('rail')=='companion' and same:family='B_matched_Flood_close_Noah_companion' elif a['tradition']=='MT' and a['role']=='Flood start' and b['tradition'] in ['SP','LXX'] and b['role']=='Noah birth' and b.get('rail') in [None,'primary'] and same:family='C_matched_Flood_start_Noah_primary' elif a['tradition']=='MT' and a['role']=='Noah death' and b['tradition']=='SP' and b['role']=='Noah birth' and b.get('rail')=='companion':family='D_Noah_death_alias' elif a['tradition']=='MT' and a['role']=='Noah death' and b['tradition']=='SP' and b['role']=='Shem birth' and b.get('rail')=='companion':family='E_extra_Noah_death_Shem_companion' elif a['tradition']=='SP' and a['role']=='Shem death' and a.get('rail')=='companion' and b['tradition'] in ['SP','LXX'] and b['role']=='Noah birth' and b.get('rail') in [None,'primary']:family='F_Shem_death_companion_alias' elif a['tradition'] in ['SP','LXX'] and a['role']=='Shem death' and a.get('rail') in [None,'primary'] and b['tradition']=='SP' and b['role']=='Noah birth' and b.get('rail')=='companion':family='G_Shem_death_primary_alias' row={'lower_record':i,'upper_record':j,'coordinates':[x,y],'family':family,'delta_context':{k:b[k]-a[k] for k in keys}} labels.append(row) if family is None: group=(a['tradition'],a['role'],a.get('rail'),b['tradition'],b['role'],b.get('rail'),*(b[k]-a[k] for k in keys));residual[group].append(row) for row in labels:check('gap_'+str(row['lower_record'])+'_'+str(row['upper_record']),r[row['upper_record']]['center']-r[row['lower_record']]['center']==1250) residual_groups=[{'signature':list(k),'count':len(v),'coordinate_pairs':[x['coordinates'] for x in v],'record_pairs':[[x['lower_record'],x['upper_record']] for x in v]} for k,v in sorted(residual.items(),key=lambda z:str(z[0]))] check('complete_partition',all(l['family'] is not None for l in labels)) equations={'A':[600,650],'B':[601,650,-1],'C':[600,650],'D':[950,650,-130,-215,-4,-1],'E':[450,650,215,-60,-4,-1],'F':[1100,-130,60,215,4,1],'G':[1100,215,-60,-4,-1]} vectors={'D':[-2,-1,0,-1],'E':[-2,0,-1,1],'F':[2,-1,1,1],'G':[-2,0,-1,1]} for family,terms in equations.items():check('equation_'+family,sum(terms)==1250) for l in labels: f=l['family'][0] if f in vectors:check('context_'+str(l['lower_record'])+'_'+str(l['upper_record']),[l['delta_context'][k] for k in keys]==vectors[f]) mainsets=[{tuple(l['coordinates']) for l in labels if l['family'].startswith(f)} for f in ['A','B','C']] check('72_main_coordinate_pairs',len(set.union(*mainsets))==sum(map(len,mainsets))==72) outputs=[] for h in load('C470_DATA.json')['admitted_expansions']: outputs.append({'pair':h['output_pair'],'second_pivot':h['second_pivot'],'complete_2K_predecessor':bool(h['complete_predecessors']),'label_classifications':[l for l in labels if l['coordinates']==h['output_pair']]}) return {'step':'C472','coordinate_pairs':pairs,'label_pairs':labels,'source_equations':equations,'residual_groups':residual_groups,'admitted_E_outputs':outputs,'family_summary':[{'family':f,'label_pairs':sum(l['family']==f for l in labels),'coordinate_pairs':len({tuple(l['coordinates']) for l in labels if l['family']==f})} for f in sorted({l['family'] for l in labels})],'counts':{'coordinate_pairs':len(pairs),'label_pairs':len(labels),'A_labels':sum(l['family']=='A_matched_Shem' for l in labels),'B_labels':sum(l['family']=='B_matched_Flood_close_Noah_companion' for l in labels),'remaining_labels':sum(l['family'] is None for l in labels),'remaining_signature_groups':len(residual_groups),'A_coordinate_pairs':len({tuple(l['coordinates']) for l in labels if l['family']=='A_matched_Shem'}),'B_coordinate_pairs':len({tuple(l['coordinates']) for l in labels if l['family']=='B_matched_Flood_close_Noah_companion'})}}