Kissing numbers
Improve the bounds on kissing numbers in dimensions up to 48, starting with dimension 5, where 40 ≤ τ(5) ≤ 44.

| 1 | #!/usr/bin/env python3 |
| 2 | """The project's judge: every candidate (*.json with "vectors") in the route's folder, checked exactly by kissing.py. |
| 3 | Both are in checks/judge/, which a check runs at the project's approved version. |
| 4 | |
| 5 | usage: check.py FOLDER [DIMENSION]. A sub-problem passes its dimension, which every candidate must have; the tree's |
| 6 | root passes none and takes all four. One line per candidate, then the best count in each dimension. It writes |
| 7 | metrics.json here: the score is the best count for a sub-problem, and for the root the number of dimensions in which |
| 8 | the best count reaches the record. Fails when a candidate is unreadable, malformed or invalid.""" |
| 9 | import json |
| 10 | import pathlib |
| 11 | import sys |
| 12 | |
| 13 | from kissing import RECORD, CandidateError, vectors, verify |
| 14 | |
| 15 | root = pathlib.Path(sys.argv[1]) |
| 16 | dims = (int(sys.argv[2]),) if len(sys.argv) > 2 else tuple(RECORD) |
| 17 | best, bad = {}, 0 |
| 18 | for path in sorted(root.rglob("*.json")) if root.exists() else []: |
| 19 | name = path.relative_to(root) |
| 20 | try: |
| 21 | candidate = json.loads(path.read_text()) |
| 22 | except Exception as exc: |
| 23 | print(f"{name}: unreadable ({exc})") |
| 24 | bad += 1 |
| 25 | continue |
| 26 | if not isinstance(candidate, dict) or "vectors" not in candidate: |
| 27 | continue |
| 28 | try: |
| 29 | d, vs = vectors(candidate, dims) |
| 30 | verify(vs) |
| 31 | except CandidateError as exc: |
| 32 | print(f"{name}: invalid: {exc}") |
| 33 | bad += 1 |
| 34 | continue |
| 35 | print(f"d={d}: {len(vs)} vectors ({name})") |
| 36 | if len(vs) > best.get(d, (0,))[0]: |
| 37 | best[d] = (len(vs), name) |
| 38 | if best: |
| 39 | reached = sum(best[d][0] >= RECORD[d] for d in best) |
| 40 | if len(dims) == 1: |
| 41 | (d,) = dims |
| 42 | score, summary = best[d][0], f"{best[d][0]} vectors in dimension {d} ({best[d][1]}); the record is {RECORD[d]}" |
| 43 | else: |
| 44 | score, summary = reached, "; ".join(f"d{d}: {best[d][0]}" for d in sorted(best)) + f"; {reached} of {len(dims)} dimensions at the record or above" |
| 45 | pathlib.Path("metrics.json").write_text(json.dumps({"score": score, "score_exact": str(score), "subtasks": {f"d{d}": best[d][0] for d in sorted(best)}}) + "\n") |
| 46 | print(summary) |
| 47 | else: |
| 48 | print(f"no valid candidates: {bad} failed" if bad else "no candidates to check") |
| 49 | sys.exit(1 if bad else 0) |