#!/usr/bin/env python3 """Job #1918 ledger: what IS the kill-class step count on a tile gap word? Definitions used (propagated from the served lane's own reading, see REPORT.md): tile T_x : residues a mod P_x with a(a+2) coprime to P_x, P_x = prod of odd primes <= x gap word : cyclic differences of the sorted residues (all gaps even; measured below) fold p : a kill-class gap is g with g = 0, +-2 (mod p) (free-translate okPair) run : maximal cyclic run of consecutive kill-class gaps counts : A = #kill-class gaps = sum L*count(L); steps = sum (L-1)*count(L) All arithmetic is exact integer arithmetic. No sampling. """ import json import sys PRIMES = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41] def tile(x): """Admissible residues of the twin-slot class {0,-2} mod P_x, and P_x.""" res = [1] # odd residues mod 2 P = 2 for q in PRIMES: if q > x: break nxt = [] for r in res: b = r for _ in range(q): if b % q and (b + 2) % q: nxt.append(b) b += P res = nxt P *= q return sorted(res), P def gap_word(res, P): n = len(res) return [res[i + 1] - res[i] for i in range(n - 1)] + [res[0] + P - res[-1]] def killclass(gaps, p): return [1 if (g % p == 0 or g % p == 2 or g % p == p - 2) else 0 for g in gaps] def spectrum(flags): """Cyclic run-length spectrum and the two step counts (no numpy, one pass).""" n = len(flags) if not any(flags): return {}, 0, 0 if all(flags): return {n: 1}, n, n - 1 start = flags.index(0) spec, run = {}, 0 for k in range(1, n + 1): if flags[(start + k) % n]: run += 1 else: if run: spec[run] = spec.get(run, 0) + 1 run = 0 if run: spec[run] = spec.get(run, 0) + 1 A = sum(L * c for L, c in spec.items()) steps = sum((L - 1) * c for L, c in spec.items()) return dict(sorted(spec.items())), A, steps CHECKS = [] def check(name, got, want): ok = got == want CHECKS.append((name, ok, got, want)) print(f"{'PASS' if ok else 'FAIL'} {name}: got={got} want={want}") rows = {} for x in (13, 17, 19, 23): res, P = tile(x) gaps = gap_word(res, P) D = len(gaps) prod = 1 for q in PRIMES: if q > x: break prod *= (q - 2) check(f"D(T{x}) = prod(q-2)", D, prod) check(f"sum gaps = P({x})", sum(gaps), P) check(f"T{x}: all gaps even", all(g % 2 == 0 for g in gaps), True) g6 = sum(1 for g in gaps if g % 6 == 0) print(f"info T{x}: D={D} P={P} gaps divisible by 6: {g6}/{D} min={min(gaps)} max={max(gaps)}") rows[x] = {"D": D, "P": P, "div6": g6, "gmin": min(gaps), "gmax": max(gaps)} for p in [q for q in PRIMES if q > x][:2]: flags = killclass(gaps, p) spec, A, steps = spectrum(flags) pred = 3 * D / p rows[x][f"p{p}"] = {"A": A, "steps": steps, "spectrum": spec, "A_over_3Dp": round(A / pred, 6), "steps_over_D": round(steps / D, 6), "n_runs": sum(spec.values())} print(f"info T{x} fold p={p}: A={A} (3D/p={pred:.3f}, ratio {A/pred:.6f}) " f"runs={sum(spec.values())} steps={steps} spec={spec}") # --- decisive control: reproduce the served lane's published T19-by-23 runs-of-3 = 62 res19, P19 = tile(19) spec19, A19, steps19 = spectrum(killclass(gap_word(res19, P19), 23)) check("T19 folded by 23: number of length-3 runs (published 62)", spec19.get(3, 0), 62) print(f"info T19/23 spectrum = {spec19} (A={A19}, steps={steps19})") # --- decisive arithmetic: what the predecessor's pre-registered target implies D29 = 214708725 print(f"info 3*D(T29)/31 = {3 * D29 // 31} (exact quotient {3 * D29 / 31})") check("pre-registered target 8 025 014 is NOT 3*D(T29)/31", 3 * D29 / 31 == 8025014, False) print(f"info 8 025 014 / D(T29) = {8025014 / D29:.6f}") for x in (19, 23): r = rows[x] for k, v in r.items(): if k.startswith("p"): print(f"info calibrated: T{x}/{k}: steps/D = {v['steps'] / r['D']:.6f}, A/D = {v['A'] / r['D']:.6f}") nfail = sum(1 for _, ok, _, _ in CHECKS if not ok) print(f"\n{'ALL PASS' if nfail == 0 else 'FAILURES'}: {len(CHECKS) - nfail}/{len(CHECKS)}") json.dump({"rows": rows, "checks": [{"name": n, "pass": ok} for n, ok, _, _ in CHECKS]}, open("job1918-rows.json", "w"), indent=1, sort_keys=True) sys.exit(0)