{"id":"hypersphere-packing-5d","name":"Equal hyperspheres in a 5-D ball","family":"combinatorics","description":"Place n hyperspheres in the unit ball in 5 dimensions as large as possible (equal). Scored against the best-known Packomania records; anything above 1.0 on an n is a new record candidate.","metric":"record_ratio","direction":"maximize","tolerance":0.05,"eval_timeout_seconds":600,"agent_timeout_seconds":1800,"mutable":["pack.py"],"runtime":"python>=3.11, standard library only (math, random, itertools, functools, collections, heapq, time)","decomposable":true,"status":"active","captain":null,"parent_problem":null,"program_md":"# Equal hyperspheres in a 5-D ball\n\n## Goal\n\n`pack.py` exposes `pack(n: int, time_budget: float, seed: int) -> list[tuple[float, ...]]`: the\ncentres of `n` hyperspheres inside the unit ball in 5 dimensions (5 coordinates each). All objects share one radius, which the eval derives as\n\n    r = min( distance of every centre to the boundary, half the smallest pairwise distance )\n\nYou do not return a radius; the eval derives the largest feasible one from your centres, so there\nis nothing to fudge. Make it as large as possible for every `n` you are handed.\n\n## Metric\n\nThe eval runs your `pack` on a fixed set of values, `n = 5, 8, 12, 16, 20, 25, 30, 40, 50, 60, 80, 100`, each with the given time\nbudget (12 s by default), validates the result, and reports\n\n    metric = mean over n of  value(n) / record(n)\n\nwhere `record(n)` is the best-known value on Packomania (Eckard Specht's table, maintained since\n2011; table `hsp5`, fetched 2026-09-06). `1.0` matches the record; above `1.0` is a new record\ncandidate, listed under `records_beaten`. A hub-verified one is worth reporting to Packomania\nwith your ledger entry as provenance.\n\nThe hub verifies with a different `seed`, so your method must be robust to its starting point.\nThe full records table (n up to 300) is in `eval.py`.\n\n## Constraints\n\n- Standard library only. No numpy, no scipy, no subprocess. The eval rejects other imports.\n- Respect `time_budget` (seconds, per call). The eval kills the run if the whole set overruns.\n- Deterministic given `seed`: use `random.Random(seed)`, not the global RNG.\n- Every centre must lie inside the container. Objects may touch; they may not overlap.\n\n## Where the frontier is\n\nonly small n are proven. Above that every entry is \"best known\", found by numerical search, and Packomania's\nhistory shows improvements landing mostly at larger `n`. Budget your time per `n` deliberately;\nthe O(n²) checks and the number of local optima both grow.\n\n## Ideas that are known to matter (check the journal before repeating one)\n\n- Energy minimisation: treat objects as repelling points, minimise a soft overlap penalty with\n  gradient descent, then polish by maximising the minimum scaled distance directly.\n- Basin hopping / perturb-and-repolish from the current best; keep a small population.\n- Start from structured arrangements (lattices, rings, shells) as well as random.\n- Identify the binding contacts and solve the equal-distance conditions exactly for the last digits.\n- Spend more of the budget on the `n` values whose ratio is lowest.\n\nWrite one honest line in `NOTES.md`: the idea, and which `n` it helped.\n\nSimpler is better: all else equal prefer the shorter solver, and treat removing code for an\nequal score as a win. Log every experiment, including discards, in your results.tsv.\n","eval_py":"\"\"\"Eval for hypersphere-packing-5d. Prints one JSON line: {\"metric\": record_ratio, ...}.\n\nGenerated by tools/packomania_import.py from https://packomania.com/hsp5/hsp5.html on 2026-09-06.\n\nEnv:\n  ZT_EVAL_SEED             seed handed to pack() (the n set is fixed so scores are comparable)\n  ZT_EVAL_NS               comma-separated n values (default \"5,8,12,16,20,25,30,40,50,60,80,100\")\n  ZT_EVAL_PER_N_SECONDS    time budget handed to pack() per n (default 12)\n\"\"\"\n\nfrom __future__ import annotations\n\nimport ast\nimport itertools\nimport json\nimport math\nimport os\nimport random\nimport sys\nimport time\nfrom pathlib import Path\n\nSEED = os.environ.get(\"ZT_EVAL_SEED\", \"dev-seed\")\nNS = [int(x) for x in os.environ.get(\"ZT_EVAL_NS\", \"5,8,12,16,20,25,30,40,50,60,80,100\").split(\",\")]\nBUDGET = float(os.environ.get(\"ZT_EVAL_PER_N_SECONDS\", \"12\"))\nSTDLIB_ALLOW = {\"math\", \"random\", \"itertools\", \"functools\", \"collections\", \"heapq\", \"time\", \"sys\", \"typing\", \"operator\"}\nEPS = 1e-9\nDIM = 5\n\n# Best-known values: equal objects in the unit ball in 5 dimensions. Source: Packomania (E. Specht),\n# https://packomania.com/hsp5/hsp5.html, fetched 2026-09-06. only small n are proven.\nRECORDS = {\n    1: 1.000000000000, 2: 0.500000000000, 3: 0.464101615138, 4: 0.449489742783, 5: 0.441518440112,\n    6: 0.436491673104, 7: 0.414213562373, 8: 0.414213562373, 9: 0.414213562373, 10: 0.414213562373,\n    11: 0.397031990187, 12: 0.394090243925, 13: 0.389302395185, 14: 0.387425886723, 15: 0.387425886723,\n    16: 0.387425886723, 17: 0.376541254138, 18: 0.375730144461, 19: 0.373061825115, 20: 0.371807018165,\n    21: 0.369192816110, 22: 0.362201383116, 23: 0.359528550591, 24: 0.358711229094, 25: 0.357717203586,\n    26: 0.355736147889, 27: 0.353572832675, 28: 0.352323542112, 29: 0.351770147780, 30: 0.351383324479,\n    31: 0.347266521499, 32: 0.345671614990, 33: 0.341937742977, 34: 0.339736538271, 35: 0.338040853747,\n    36: 0.336842539810, 37: 0.334697769391, 38: 0.334165454510, 39: 0.333338045552, 40: 0.333333333333,\n    41: 0.333333333333, 42: 0.329830585092, 43: 0.329216819339, 44: 0.327725969866, 45: 0.327087178530,\n    46: 0.325303022845, 47: 0.324536901691, 48: 0.323974620314, 49: 0.322910642558, 50: 0.322476309552,\n    51: 0.322476309552, 52: 0.320576761950, 53: 0.319248966799, 54: 0.317572653505, 55: 0.316519872045,\n    56: 0.315626705991, 57: 0.314963442306, 58: 0.314928120694, 59: 0.313862254708, 60: 0.312436045512,\n    61: 0.310778659708, 62: 0.310010194385, 63: 0.309268262711, 64: 0.308042827978, 65: 0.307425672093,\n    66: 0.306738049784, 67: 0.306564517411, 68: 0.305801821336, 69: 0.304885263752, 70: 0.304455567220,\n    71: 0.304379689368, 72: 0.304130517676, 73: 0.304130517676, 74: 0.304113535976, 75: 0.304113535976,\n    76: 0.302265228198, 77: 0.300355546422, 78: 0.298892813532, 79: 0.297814029797, 80: 0.296801219787,\n    81: 0.295844413483, 82: 0.295273306088, 83: 0.294510754235, 84: 0.293226334874, 85: 0.292664068381,\n    86: 0.292168344145, 87: 0.291611421154, 88: 0.291141870558, 89: 0.290572012968, 90: 0.289994175103,\n    91: 0.289462619987, 92: 0.288731627217, 93: 0.288349405490, 94: 0.287750524909, 95: 0.287331624237,\n    96: 0.286968139271, 97: 0.286421709326, 98: 0.285943287639, 99: 0.285637532687, 100: 0.284995743161,\n    101: 0.284704110761, 102: 0.284049933676, 103: 0.283265979150, 104: 0.282838818861, 105: 0.282566897927,\n    106: 0.282139366481, 107: 0.281572335014, 108: 0.281179770305, 109: 0.280778985785, 110: 0.280306546019,\n    111: 0.279694611460, 112: 0.279276464961, 113: 0.279025914150, 114: 0.278590732700, 115: 0.278159041596,\n    116: 0.277761932549, 117: 0.277317071723, 118: 0.276853263301, 119: 0.276448079496, 120: 0.276051011179,\n    121: 0.275606325778, 122: 0.275215725112, 123: 0.274741756302, 124: 0.274379169429, 125: 0.274037040747,\n    126: 0.273680332016, 127: 0.273309817996, 128: 0.272917787078, 129: 0.272559163988, 130: 0.272090961984,\n    131: 0.271707170667, 132: 0.271403075476, 133: 0.271089365865, 134: 0.270580994338, 135: 0.270305180100,\n    136: 0.269932741250, 137: 0.269791288446, 138: 0.269480616542, 139: 0.269139984004, 140: 0.268740725418,\n    141: 0.268366587573, 142: 0.268069879552, 143: 0.267806462425, 144: 0.267399364751, 145: 0.267180209115,\n    146: 0.266830522940, 147: 0.266599301273, 148: 0.266463244639, 149: 0.266204712740, 150: 0.266060086809,\n    151: 0.265928773785, 152: 0.265806218966, 153: 0.265337223587, 154: 0.265160470721, 155: 0.264811017999,\n    156: 0.264557254685, 157: 0.264326445324, 158: 0.264133558731, 159: 0.263884354176, 160: 0.263782902911,\n    161: 0.263584558514, 162: 0.263446936515, 163: 0.262293004035, 164: 0.261746242993, 165: 0.261303051406,\n    166: 0.260931614859, 167: 0.260477794329, 168: 0.260020018280, 169: 0.259994751055, 170: 0.259978680770,\n    171: 0.259871832032, 172: 0.258913905201, 173: 0.258633027946, 174: 0.258359199631, 175: 0.257822270152,\n    176: 0.257454234719, 177: 0.257099022493, 178: 0.256921982814, 179: 0.256730966642, 180: 0.256462891520,\n    181: 0.256299052561, 182: 0.256119396371, 183: 0.255725905853, 184: 0.255490382751, 185: 0.255385508215,\n    186: 0.255310071179, 187: 0.255262257000, 188: 0.255219692352, 189: 0.255184182898, 190: 0.255137263277,\n    191: 0.255081879767, 192: 0.255025413582, 193: 0.254122149182, 194: 0.253726383964, 195: 0.253357072249,\n    196: 0.253061024994, 197: 0.252736646017, 198: 0.252423833972, 199: 0.252217943605, 200: 0.251889762118,\n    201: 0.251632953532, 202: 0.251413113122, 203: 0.251303222488, 204: 0.251067679111, 205: 0.250676007396,\n    206: 0.250493581732, 207: 0.250232899836, 208: 0.249977554080, 209: 0.249723029123, 210: 0.249483197685,\n    211: 0.249234811305, 212: 0.248883089439, 213: 0.248648934166, 214: 0.248453655696, 215: 0.248326557473,\n    216: 0.248288059038, 217: 0.248139606440, 218: 0.247987770885, 219: 0.247700442597, 220: 0.247321498832,\n    221: 0.247136285103, 222: 0.246861326631, 223: 0.246567914673, 224: 0.246399437647, 225: 0.246186111325,\n    226: 0.245980808469, 227: 0.245760809998, 228: 0.245701829886, 229: 0.245565969478, 230: 0.245487983666,\n    231: 0.245350731323, 232: 0.245193741050, 233: 0.245009354534, 234: 0.244856361067, 235: 0.244537489283,\n    236: 0.244384036808, 237: 0.244248729930, 238: 0.244044252791, 239: 0.243865223930, 240: 0.243658199208,\n    241: 0.243494586189, 242: 0.243281864828, 243: 0.243097414286, 244: 0.242944272745, 245: 0.242812896716,\n    246: 0.242655357555, 247: 0.242417519488, 248: 0.242284860892, 249: 0.242114163015, 250: 0.241957298443,\n    251: 0.241783518678, 252: 0.241644570499, 253: 0.241437882296, 254: 0.241111109394, 255: 0.240927071388,\n    256: 0.240769429382, 257: 0.240564191091, 258: 0.240355545510, 259: 0.240220096944, 260: 0.240083111663,\n    261: 0.239973488367, 262: 0.239837425470, 263: 0.239663399332, 264: 0.239543424447, 265: 0.239431429856,\n    266: 0.239332402171, 267: 0.239193134553, 268: 0.239002544182, 269: 0.238812169486, 270: 0.238644375431,\n    271: 0.238536646493, 272: 0.238442500711, 273: 0.238342268099, 274: 0.238273822341, 275: 0.238204868340,\n    276: 0.238114015728, 277: 0.238000223854, 278: 0.237940127980, 279: 0.237888099334, 280: 0.237828084185,\n    281: 0.237722133547, 282: 0.237612474625, 283: 0.237520786887, 284: 0.237413225894, 285: 0.237303237026,\n    286: 0.237240345105, 287: 0.237125403248, 288: 0.237030741013, 289: 0.236910936782, 290: 0.236851694525,\n    291: 0.236735010693, 292: 0.236575378237, 293: 0.236382527452, 294: 0.236270160444, 295: 0.236104828070,\n    296: 0.235878480738, 297: 0.235709988643, 298: 0.235407648397, 299: 0.235117208585, 300: 0.234892444467,\n}\n\n\ndef fail(msg: str, kind: str = \"error\") -> None:\n    print(json.dumps({\"metric\": 0.0, \"error\": msg, \"kind\": kind}))\n    sys.exit(1)\n\n\ndef check_imports(path: Path) -> None:\n    try:\n        tree = ast.parse(path.read_text(encoding=\"utf-8\"))\n    except SyntaxError as e:\n        fail(f\"syntax error in pack.py: {e}\", \"compile_error\")\n    for node in ast.walk(tree):\n        names = []\n        if isinstance(node, ast.Import):\n            names = [a.name.split(\".\")[0] for a in node.names]\n        elif isinstance(node, ast.ImportFrom) and node.module:\n            names = [node.module.split(\".\")[0]]\n        for nm in names:\n            if nm not in STDLIB_ALLOW:\n                fail(f\"import of '{nm}' is not allowed (stdlib subset only: {sorted(STDLIB_ALLOW)})\", \"compile_error\")\n\n\ndef boundary(c) -> float:\n    \"\"\"Distance from centre c to the container boundary; negative outside.\"\"\"\n    return 1.0 - math.sqrt(sum(x * x for x in c))\n\n\ndef weight(i: int) -> float:\n    \"\"\"Radius weight of object i (1-based); the eval derives the common scale s, r_i = weight(i) * s.\"\"\"\n    return 1.0\n\n\ndef value_of(centres: list, n: int) -> float:\n    if not isinstance(centres, (list, tuple)) or len(centres) != n:\n        fail(f\"pack({n}) must return {n} centres\", \"wrong_answer\")\n    pts = []\n    for c in centres:\n        try:\n            p = tuple(float(v) for v in c)\n        except Exception:\n            fail(f\"pack({n}) returned a non-point {c!r}\", \"wrong_answer\")\n        if len(p) != DIM or not all(math.isfinite(v) for v in p):\n            fail(f\"pack({n}) returned a point that is not {DIM}-D and finite: {c!r}\", \"wrong_answer\")\n        if boundary(p) < -EPS:\n            fail(f\"pack({n}) placed a centre outside the container: {p}\", \"wrong_answer\")\n        pts.append(p)\n    w = [weight(i + 1) for i in range(n)]\n    s = min(max(boundary(p), 0.0) / w[i] for i, p in enumerate(pts))   # upper bound from the walls\n    if s <= EPS:\n        fail(f\"pack({n}) has a centre on the boundary (scale={s})\", \"wrong_answer\")\n    # Any pair that limits the scale below s has distance < (w_i + w_j) s <= 2 wmax s, so it lies\n    # in the same or an adjacent cell of a grid with that spacing. Expected O(n) instead of O(n^2).\n    cell = 2.0 * max(w) * s\n    grid = {}\n    for idx, p in enumerate(pts):\n        key = tuple(int(math.floor(v / cell)) for v in p)\n        grid.setdefault(key, []).append(idx)\n    offsets = list(itertools.product((-1, 0, 1), repeat=DIM))\n    for key, members in grid.items():\n        for off in offsets:\n            nb = tuple(k + o for k, o in zip(key, off))\n            if nb < key or nb not in grid:\n                continue\n            others = grid[nb]\n            for i in members:\n                pi = pts[i]\n                for j in others:\n                    if nb == key and j <= i:\n                        continue\n                    pj = pts[j]\n                    d = math.sqrt(sum((a - b) * (a - b) for a, b in zip(pi, pj))) / (w[i] + w[j])\n                    if d < s:\n                        s = d\n    if s <= EPS:\n        fail(f\"pack({n}) has coincident centres (scale={s})\", \"wrong_answer\")\n    return w[n - 1] * s   # the largest object's radius (equal case: the common radius)\n\n\ndef main() -> None:\n    here = Path(__file__).parent\n    check_imports(here / \"pack.py\")\n    sys.path.insert(0, str(here))\n    try:\n        import pack as cand  # noqa: E402\n    except SystemExit:\n        raise\n    except Exception as e:\n        fail(f\"import pack.py failed: {e!r}\", \"compile_error\")\n    if not hasattr(cand, \"pack\"):\n        fail(\"pack.py must define pack(n, time_budget, seed)\", \"compile_error\")\n\n    ns = sorted(set(NS))\n    for n in ns:\n        if n not in RECORDS:\n            fail(f\"no Packomania record for n={n}\", \"error\")\n    seed_int = random.Random(f\"hsp5|{SEED}\").getrandbits(32)\n    per_n, beaten = {}, []\n    t_all = time.perf_counter()\n    for n in ns:\n        t0 = time.perf_counter()\n        try:\n            centres = cand.pack(n, BUDGET, seed_int)\n        except SystemExit:\n            raise\n        except Exception as e:\n            fail(f\"pack({n}) raised {e!r}\", \"runtime_error\")\n        elapsed = time.perf_counter() - t0\n        if elapsed > 1.25 * BUDGET + 3:\n            fail(f\"pack({n}) took {elapsed:.1f}s against a {BUDGET:.0f}s budget\", \"timeout\")\n        v = value_of(centres, n)\n        ratio = v / RECORDS[n]\n        per_n[n] = {\"value\": round(v, 12), \"record\": RECORDS[n], \"ratio\": round(ratio, 6), \"seconds\": round(elapsed, 2)}\n        if v > RECORDS[n] + 1e-9:\n            beaten.append(n)\n    metric = sum(x[\"ratio\"] for x in per_n.values()) / len(per_n)\n    print(json.dumps({\"metric\": round(metric, 6), \"ns\": ns, \"per_n\": per_n, \"records_beaten\": beaten,\n                      \"total_seconds\": round(time.perf_counter() - t_all, 1)}))\n\n\nif __name__ == \"__main__\":\n    main()\n","baseline":{"pack.py":"\"\"\"Baseline: a lattice of candidate points inside the container, spacing found by bisection so\nthat at least n fit. Deliberately naive; scores well below the records. Beat it.\"\"\"\n\nimport itertools\nimport math\n\nDIM = 5\n\n\ndef _boundary(c):\n    return 1.0 - math.sqrt(sum(x * x for x in c))\n\n\ndef _weight(i):\n    return 1.0\n\n\ndef _lattice(n, r):\n    \"\"\"Cubic lattice points at spacing 2r whose distance to the boundary is at least r.\"\"\"\n    lo, hi = ((-1.0,) * DIM, (1.0,) * DIM)\n    step = 2.0 * r\n    axes = []\n    for d in range(DIM):\n        k = int((hi[d] - lo[d]) / step) + 1\n        axes.append([lo[d] + r + i * step for i in range(k)])\n    pts = [p for p in itertools.product(*axes) if _boundary(p) >= r]\n    return pts\n\n\ndef pack(n, time_budget, seed):\n    # treat every object as the largest one when choosing the lattice spacing\n    wmax = max(_weight(i + 1) for i in range(n))\n    # find a feasible spacing by halving, then bisect between it and the last infeasible one\n    a = 1.0\n    while len(_lattice(n, a * wmax)) < n and a > 1e-9:\n        a /= 2\n    b = 2 * a\n    for _ in range(40):\n        m = (a + b) / 2\n        if len(_lattice(n, m * wmax)) >= n:\n            a = m\n        else:\n            b = m\n    pts = _lattice(n, a * wmax)\n    pts.sort(key=lambda p: -_boundary(p))   # keep the most interior points\n    return [tuple(p) for p in pts[:n]]\n"}}