"""本主题专属离线算法，仅读取同目录合成JSON，不联网、不控制设备。"""
import csv, json, math, re, struct
from pathlib import Path
from fractions import Fraction
BASE=Path(__file__).resolve().parent
data=json.loads((BASE/'input.json').read_text(encoding='utf-8'))['data']
h=data['full_height'];assert h%2==0
f0=list(range(0,h,2));f1=list(range(1,h,2))
merged=[v for pair in zip(f0,f1) for v in pair]
assert merged==list(range(h))
result={'field_0_model_rows':f0,'field_1_model_rows':f1,'stored_rows_per_field':h//2,'reconstructed_rows':merged,'hardware_field_order_measured':False}
(BASE/'result.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
print(json.dumps(result,ensure_ascii=False))
