The Erdős minimum overlap problem
Pin down the constant c ≈ 0.38 such that every split of {1,…,2N} into equal halves has a difference occurring cN times.

| 1 | #!/usr/bin/env python3 |
| 2 | """The project's judge: every certificate (*.json with "values") in the route's folder, verified exactly by |
| 3 | verify_overlap.py. Both are in checks/judge/, which a check runs at the project's approved version. One line per |
| 4 | certificate, then the best bound; metrics.json in the working directory gets the best bound as the score (lower is |
| 5 | better). Fails when a certificate is unreadable or not admissible.""" |
| 6 | import json |
| 7 | import os |
| 8 | import pathlib |
| 9 | import sys |
| 10 | |
| 11 | from verify_overlap import CertificateError, certify, decimal_up |
| 12 | |
| 13 | root = pathlib.Path(sys.argv[1]) |
| 14 | best, bad = None, 0 |
| 15 | for path in sorted(root.rglob("*.json")) if root.exists() else []: |
| 16 | name = path.relative_to(root) |
| 17 | try: |
| 18 | cert = json.loads(path.read_text()) |
| 19 | except Exception as exc: |
| 20 | print(f"{name}: unreadable ({exc})") |
| 21 | bad += 1 |
| 22 | continue |
| 23 | if not isinstance(cert, dict) or "values" not in cert: |
| 24 | continue |
| 25 | try: |
| 26 | result = certify(cert) |
| 27 | except CertificateError as exc: |
| 28 | print(f"{name}: not admissible: {exc}") |
| 29 | bad += 1 |
| 30 | continue |
| 31 | print(f"{name}: n={result['n']}, mu <= {decimal_up(result['bound'])}") |
| 32 | if best is None or result["bound"] < best[0]: |
| 33 | best = (result["bound"], name) |
| 34 | if best: |
| 35 | pathlib.Path(os.getcwd(), "metrics.json").write_text(json.dumps({"score": float(best[0]), "score_exact": decimal_up(best[0])})) |
| 36 | print(f"best upper bound {decimal_up(best[0])} ({best[1]})" if best else "no certificates to check") |
| 37 | sys.exit(1 if bad else 0) |