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 second judge, the check `improves`, which informs and does not block a merge: the pushed route's best |
| 3 | certificate against the best the default branch holds (constructions/ and routes/ of the check's own checkout, the |
| 4 | approved version) and against the best known bound. It says by how much the route improves on the default branch and |
| 5 | passes when that is at least the minimum improvement, 1e-7 (EinsteinArena's for first place on this problem); a route |
| 6 | at least that far below the best known bound is a new result. On the default branch itself it reports what it holds |
| 7 | and passes.""" |
| 8 | import json |
| 9 | import os |
| 10 | import pathlib |
| 11 | import sys |
| 12 | from fractions import Fraction |
| 13 | |
| 14 | from verify_overlap import CertificateError, certify, decimal_up |
| 15 | |
| 16 | MINIMUM = Fraction("1e-7") |
| 17 | KNOWN = "0.3808564043546676" # the EinsteinArena leader, NIGHTFALL-DevinWright, 2026-10-20 (the README's known bounds) |
| 18 | |
| 19 | |
| 20 | def show(x): |
| 21 | return f"{float(x):.3g}".replace("e-0", "e-") |
| 22 | |
| 23 | |
| 24 | def best(roots): |
| 25 | out = None |
| 26 | for root in roots: |
| 27 | for path in sorted(root.rglob("*.json")) if root.exists() else []: |
| 28 | try: |
| 29 | cert = json.loads(path.read_text()) |
| 30 | except Exception: |
| 31 | continue |
| 32 | if not isinstance(cert, dict) or "values" not in cert: |
| 33 | continue |
| 34 | try: |
| 35 | result = certify(cert) |
| 36 | except CertificateError: |
| 37 | continue |
| 38 | if out is None or result["bound"] < out[0]: |
| 39 | out = (result["bound"], path) |
| 40 | return out |
| 41 | |
| 42 | |
| 43 | |
| 44 | main_dir = pathlib.Path(sys.argv[2]) |
| 45 | held = best([main_dir / "constructions", main_dir / "routes"]) |
| 46 | if os.environ.get("SS_ROUTE_DIR", "") == "routes": |
| 47 | print(f"the default branch holds best upper bound {decimal_up(held[0])}" if held else "the default branch holds no certificate") |
| 48 | sys.exit(0) |
| 49 | route = best([pathlib.Path(sys.argv[1])]) |
| 50 | if not route: |
| 51 | print("no certificate in this route to compare") |
| 52 | sys.exit(1) |
| 53 | this = f"best upper bound {decimal_up(route[0])} ({route[1].name})" |
| 54 | known = f"a new result, {show(Fraction(KNOWN) - route[0])} below the best known {KNOWN}" if Fraction(KNOWN) - route[0] >= MINIMUM else f"not a new result: the best known is {KNOWN}" |
| 55 | gain = held[0] - route[0] if held else None |
| 56 | if gain is None: |
| 57 | print(f"improves on the default branch, which holds no certificate: {this}; {known}") |
| 58 | elif gain <= 0: |
| 59 | print(f"no improvement: {this}; the default branch holds {decimal_up(held[0])}; {known}") |
| 60 | sys.exit(1) |
| 61 | elif gain < MINIMUM: |
| 62 | print(f"improves on the default branch by {show(gain)}, less than the minimum {show(MINIMUM)}: {this}, against {decimal_up(held[0])}; {known}") |
| 63 | sys.exit(1) |
| 64 | else: |
| 65 | print(f"improves on the default branch by {show(gain)} (at least {show(MINIMUM)}): {this}, against {decimal_up(held[0])}; {known}") |