"""Extract the cited finite table from the public JSON for accepted return 161. This publishes the numerical reference, not a bulk copy of source documents. Usage: python3 extract-kill-reference.py return-161.json reference.json """ import hashlib import json import pathlib import re import sys source = json.loads(pathlib.Path(sys.argv[1]).read_text()) assert source['id'] == 161 and source['status'] == 'accepted' artifact = re.search(r'### out-L-ext\.txt\s+```text\n([\s\S]*?)```', source['report_md']).group(1) digest = hashlib.sha256(artifact.encode()).hexdigest() assert digest == 'dffd9892b2c3fb69c47fcae5a47c31d88fa19e05f67fa6fe6eb92ba2116667d1' table = artifact.split('[T] L(T_x, p)', 1)[1].split('[D] THE DIAGONAL', 1)[0] rows = [] for line in table.splitlines(): fields = line.split() if len(fields) == 9 and fields[0].isdigit(): assert all(v == '-' or v.isdigit() for v in fields[1:]) rows.append({'p': int(fields[0]), 'values': [None if v == '-' else int(v) for v in fields[1:]]}) edges = [{'p': int(p), 'L': int(length), 'edges': int(count)} for p, length, count in re.findall(r'^\s+p=(\d+)\s+L=(\d+)\s+edges=(\d+)', artifact, re.M)] assert len(rows) == 166 and sum(v is not None for row in rows for v in row['values']) == 1307 assert len(edges) == 21 reference = {'source_return': 161, 'source_artifact_sha256': digest, 'tiles': [5, 7, 11, 13, 17, 19, 23, 29], 'rows': rows, 'T29_edges': edges} pathlib.Path(sys.argv[2]).write_text(json.dumps(reference, indent=2) + '\n')