#!/usr/bin/env python3 """The project's second judge, the check `improves`, which informs and does not block a merge: the pushed route's best candidate against the best the default branch holds (constructions/ and routes/ of the check's own checkout, the approved version) and against the best known bound. It says by how much the route improves on the default branch and passes when that is at least the minimum improvement, 1e-8 (EinsteinArena's on this problem); a route at least that far below the best known bound is a new result. On the default branch itself it reports what it holds and passes.""" import json import os import pathlib import sys from fractions import Fraction from autocorrelation import decimal_up, ratio MINIMUM = Fraction("1e-8") KNOWN = "1.502743486709583" # the EinsteinArena leader, Atris, seen 2026-10-22 (the README's known bounds) def show(x): return f"{float(x):.3g}".replace("e-0", "e-") def best(roots): out = None for root in roots: for path in sorted(root.rglob("*.json")) if root.exists() else []: try: candidate = json.loads(path.read_text()) if not isinstance(candidate, dict) or "heights" not in candidate: continue _, r = ratio(candidate) except (OSError, ValueError): continue if out is None or r < out[0]: out = (r, path) return out main_dir = pathlib.Path(sys.argv[2]) held = best([main_dir / "constructions", main_dir / "routes"]) if os.environ.get("SS_ROUTE_DIR", "") == "routes": print(f"the default branch holds best upper bound {decimal_up(held[0])}" if held else "the default branch holds no candidate") sys.exit(0) route = best([pathlib.Path(sys.argv[1])]) if not route: print("no candidate in this route to compare") sys.exit(1) this = f"best upper bound {decimal_up(route[0])} ({route[1].name})" 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}" gain = held[0] - route[0] if held else None if gain is None: print(f"improves on the default branch, which holds no candidate: {this}; {known}") elif gain <= 0: print(f"no improvement: {this}; the default branch holds {decimal_up(held[0])}; {known}") sys.exit(1) elif gain < MINIMUM: print(f"improves on the default branch by {show(gain)}, less than the minimum {show(MINIMUM)}: {this}, against {decimal_up(held[0])}; {known}") sys.exit(1) else: print(f"improves on the default branch by {show(gain)} (at least {show(MINIMUM)}): {this}, against {decimal_up(held[0])}; {known}")