#!/usr/bin/env python3 # -*- coding: utf-8 -*- """cover90verify.py — a THIRD, standalone checker for job #2731. Shares no code with the search or the gate: it imports nothing from cover90 and uses no numpy. It re-implements the project's own semantics in plain integer arithmetic and checks a claimed covered run position by position. Semantics (project's own): offset i is covered by prime p with residue v iff (i + v) mod p in {1, p-1}. For a claimed run [start, start+len) it proves: * every offset in the interval is covered by at least one prime (the witness), and * the two bounding offsets are NOT covered (so the run is maximal in its own range), and for a claimed hole list on a window it re-derives the holes from scratch. Exit 0 only if every claim holds. """ import argparse import json import sys PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] def covered(i, residues): for v, p in zip(residues, PRIMES[:len(residues)]): r = (i + v) % p if r == 1 or r == p - 1: return True return False def verify_run(residues, start, length, check_boundaries=True): bad = [i for i in range(start, start + length) if not covered(i, residues)] res = {"kind": "covered_run", "start": start, "length": length, "uncovered_offsets": bad[:20], "uncovered_count": len(bad), "witness": len(bad) == 0} if check_boundaries and start > 0: res["hole_before"] = not covered(start - 1, residues) res["hole_after"] = not covered(start + length, residues) res["maximal_in_range"] = bool(res["hole_before"] and res["hole_after"]) res["pass"] = res["witness"] and (not check_boundaries or res.get("maximal_in_range", True)) return res def verify_holes(residues, lo, hi, claimed): got = [i for i in range(lo, hi) if not covered(i, residues)] return {"kind": "hole_list", "lo": lo, "hi": hi, "holes": got, "claimed": claimed, "pass": got == list(claimed)} def main(): ap = argparse.ArgumentParser() ap.add_argument("--residues", required=True, help="JSON file: list, or a run/search output") ap.add_argument("--claims", required=True, help="JSON file with a list of claims") ap.add_argument("--out") a = ap.parse_args() d = json.load(open(a.residues, encoding="utf-8")) if isinstance(d, dict): res = d.get("best_residues") or d.get("residues") else: res = d claims = json.load(open(a.claims, encoding="utf-8")) results = [] for c in claims: if c["kind"] == "covered_run": results.append(verify_run(res, c["start"], c["length"], c.get("check_boundaries", True))) elif c["kind"] == "hole_list": results.append(verify_holes(res, c["lo"], c["hi"], c["claimed"])) else: raise SystemExit("unknown claim kind %r" % c["kind"]) out = {"tool": "cover90verify/1 (standalone, no shared code, no numpy)", "residues": res, "results": results, "passed": sum(1 for r in results if r["pass"]), "total": len(results)} out["ok"] = out["passed"] == out["total"] if a.out: json.dump(out, open(a.out, "w", encoding="utf-8"), indent=1) print(json.dumps(out, indent=1)) return 0 if out["ok"] else 1 if __name__ == "__main__": sys.exit(main())