"""Job #193: re-derive every printed witness run from its two endpoints alone, sharing no code with kstar-cover.c. For each output line "P#->P'# ... K* = k ... run [y0, y1]": - the level-P slots in [y0, y1] (integers y with y mod p not in {0, p-2} for every prime p <= P) are listed by trial division in Python big integers; - there must be exactly k of them, consecutive by construction, and each must be killed by an entering prime q in (P, P'] (q | y or q | y + 2). A passing line proves K* >= k at that step by exhibiting the run. It says nothing about K* + 1. usage: python3 verify_runs.py file.out [file.out ...] exit status 1 if any line fails. """ import math, re, sys def primes(lo, hi): return [p for p in range(max(2, lo), hi + 1) if all(p % d for d in range(2, math.isqrt(p) + 1))] bad = 0 for path in sys.argv[1:]: for line in open(path, encoding="utf-8"): m = re.match(r"(\d+)#->(\d+)#.*K\* = (\d+).*run \[(\d+), (\d+)\]", line) if not m: continue P, Pp, K, y0, y1 = map(int, m.groups()) base, Q = primes(2, P), primes(P + 1, Pp) run = [y for y in range(y0, y1 + 1) if all(y % p not in (0, (p - 2) % p) for p in base)] ok = len(run) == K and run[0] == y0 and run[-1] == y1 and all(any(y % q in (0, q - 2) for q in Q) for y in run) bad += not ok print(f"{P}#->{Pp}#: K* = {K}, level-{P} slots in run = {len(run)}, all killed = " f"{all(any(y % q in (0, q - 2) for q in Q) for y in run)} {'PASS' if ok else 'FAIL'}") print("all runs pass" if bad == 0 else f"{bad} run(s) FAIL") sys.exit(1 if bad else 0)