"""Which Matthew verses the Revelation ledger reaches (the figure of record), for marking three-way rows."""
import json, re, pathlib
U = pathlib.Path(__file__).resolve().parents[1]
L = json.loads((U / "map/rev-matthew-ledger.json").read_text())["rows"]

def verses(spec):
    out = set()
    for part in re.split(r";\s*", spec or ""):
        m = re.match(r"(\d+):(\d+)(?:-(\d+))?", part.strip())
        if not m: continue
        c, a, z = int(m.group(1)), int(m.group(2)), int(m.group(3) or m.group(2))
        out |= {f"{c}:{v}" for v in range(a, z + 1)}
    return out

REACH = {}
for r in L:
    for v in verses(r.get("matt")):
        REACH.setdefault(v, []).append((r.get("rev"), r.get("move"), r.get("rev_relation")))

if __name__ == "__main__":
    for v in ["26:20", "26:21", "26:23", "26:26", "26:27", "26:28", "26:29", "23:6", "19:28", "20:21", "20:23", "18:15", "18:16", "18:17", "18:20"]:
        print(v, [x[0] for x in REACH.get(v, [])])
