from fractions import Fraction as F from pathlib import Path ROOT=Path(__file__).resolve().parent.parent def run(load,check): E=F(25,23);reg=load('C286_DATA.json')['target_register'];sourced=[] for x in load('C338_DATA.json')['rows']: if not x['full_source_ladder']:continue N,R,H,Q=(x[k] for k in ['N_SP_Noah','R_MT_next_restored_Flood','H_MT_sameGear_base_Shem','F_MT_sameGear_base_Flood']);mn=[z for z in reg if z['tradition']=='MT' and z['role']=='Noah birth' and z['gear']==N['gear'] and z['Cainan']==z['Terah60']==0 and z['full430']==1];check(f'i{x["i"]} baseNoah',len(mn)==1);m=mn[0]['center'];delta,u,v,w=N['center']-m,m-H['center'],m-Q['center'],R['center']-Q['center'] check(f'i{x["i"]} source generating values',[delta,u,v,w]==[650,500,600,192]) d0,d1,d2=delta+v-w,delta+u,delta+v check(f'i{x["i"]} exact ladder derivation',[d0,d1,d2]==[1058,1150,1250] and E*d0==d1 and E*d1==d2) check(f'i{x["i"]} second stage condition',F(v-E*u,E-1)==delta) check(f'i{x["i"]} first stage restoration condition',F(d2)-F(d1)/E==w==130+60+2) sourced.append({'i':x['i'],'delta_SP_MT_base_Noah':delta,'MT_Noah_to_Shem':u,'MT_Noah_to_Flood':v,'restoration_and_adjacent_Gear':w,'duration_basis':[d0,d1,d2],'records':{'N':N,'R':R,'H':H,'F':Q,'MT_base_Noah':mn[0]}}) check('two primary rows are uniform translation',all(sourced[1]['records'][k]['center']-sourced[0]['records'][k]['center']==2 for k in sourced[0]['records'])) controls=[];death={(x['a'],x['b'],x['i']):x for x in load('C332_DATA.json')['rows']} for x in load('C319_DATA.json')['rows']: key=x['a'],x['b'],x['i'];n=[z for z in reg if z['tradition']=='SP' and z['role']=='Noah birth' and z['Cainan']==z['Terah60']==0 and z['full430']==1 and z['center']==x['n']];check(str(key)+' SPsource',len(n)==1);N=n[0];g=N['gear'];hs=[z for z in reg if z['tradition']=='MT' and z['role']=='Shem birth' and z['gear']==g and z['Cainan']==z['Terah60']==0 and z['full430']==1];fs=[z for z in reg if z['tradition']=='MT' and z['role']==('Flood start' if N['rail']=='primary' else 'Flood close') and z['gear']==g and z['Cainan']==z['Terah60']==0 and z['full430']==1];check(str(key)+' H/Fsource',len(hs)==len(fs)==1) widths=[x['n']-x['R'],x['n']-hs[0]['center'],x['n']-fs[0]['center']];full=E*widths[0]==widths[1] and E*widths[1]==widths[2] check(str(key)+' ladder criterion',full==(x['b']==2 and N['rail']=='primary')) check(str(key)+' same selector as death criteria',full==death[key]['has_both']) controls.append({'a':x['a'],'b':x['b'],'i':x['i'],'joint_admitted':x['joint_admitted'],'regular_ladder_arithmetic':full,'full_source_ladder':full and x['joint_admitted'],'two17K':x['two17K'],'widths':widths}) survivors=[{k:r[k] for k in ['a','b','i']} for r in controls if r['full_source_ladder']];joint=[{k:r[k] for k in ['a','b','i']} for r in controls if r['full_source_ladder'] and r['two17K']] check('same four surviving selections',survivors==load('C332_DATA.json')['both_survivors']) check('two17K additionally selects22',joint==load('C332_DATA.json')['both_plus_two17K_survivors']) file46=(ROOT/'sources/File_46.md').read_text();c09=(ROOT/'sources/C09_REPORT.md').read_text();c89=(ROOT/'sources/C89_REPORT.md').read_text() check('general integral double expansion','A span divisible by `23²` admits two successive integral `25/23` expansions.' in file46) check('old scalar ladder','**1058** | 1150 | 1250' in c09) check('C89 distinct sourced ladder','1400→2458 | 1906→3056 | 2456→3706' in c89) return {'step':'C342','minimal_source_inputs':sourced,'selector_controls':controls,'survivors':survivors,'survivors_plus_two17K':joint,'selector_equivalent_to_C332':True,'cumulative_choice_selected_by_regular_ladder':False,'source_binding_status':load('C334_DATA.json')['exact_endpoint_binding'],'source_operator_status':'File46 explicitly licenses two integral expansions of a23-squared multiple; no reviewed instruction prescribes this particular endpoint/context sequence.','prior_art':{'C01_C09':'Scalar ladder already recorded.','C89':'Different source placement with moving endpoints at first two stages; same final base-MT-Flood/SP-Noah interval.','current':'Noah-held MT Flood/Shem/Flood placement, its rail/mode controls and death refinement.'},'independent_witness_claim':False,'C343_scope':'Synthesis, source availability and completed-packet integrity only.'}