{"id":"hypersphere-packing-6d","name":"Equal hyperspheres in a 6-D ball","family":"combinatorics","description":"Place n hyperspheres in the unit ball in 6 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 6-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 6 dimensions (6 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 `hsp6`, 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 250) 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-6d. Prints one JSON line: {\"metric\": record_ratio, ...}.\n\nGenerated by tools/packomania_import.py from https://packomania.com/hsp6/hsp6.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 = 6\n\n# Best-known values: equal objects in the unit ball in 6 dimensions. Source: Packomania (E. Specht),\n# https://packomania.com/hsp6/hsp6.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.433030277982, 8: 0.414213562373, 9: 0.414213562373, 10: 0.414213562373,\n    11: 0.414213562373, 12: 0.414213562373, 13: 0.399733968245, 14: 0.397082036300, 15: 0.395351834250,\n    16: 0.391638462915, 17: 0.389884057230, 18: 0.387690929906, 19: 0.387392356230, 20: 0.385122550811,\n    21: 0.380913563881, 22: 0.379795897113, 23: 0.379795897113, 24: 0.379795897113, 25: 0.379795897113,\n    26: 0.379795897113, 27: 0.379795897113, 28: 0.371704582015, 29: 0.366977223241, 30: 0.366047231330,\n    31: 0.366025403784, 32: 0.366025403784, 33: 0.363988432557, 34: 0.363722695171, 35: 0.361615859266,\n    36: 0.361615859266, 37: 0.360102655988, 38: 0.359908773697, 39: 0.356729322720, 40: 0.356512683503,\n    41: 0.355887507808, 42: 0.355708416672, 43: 0.353932438080, 44: 0.352805255979, 45: 0.348654357682,\n    46: 0.347081628895, 47: 0.345832635568, 48: 0.345310658477, 49: 0.344811860477, 50: 0.344673403961,\n    51: 0.342658894533, 52: 0.342226488112, 53: 0.342114480758, 54: 0.341371969977, 55: 0.339315534967,\n    56: 0.338638480363, 57: 0.337744471879, 58: 0.337156117504, 59: 0.336378938564, 60: 0.336218074486,\n    61: 0.335158517725, 62: 0.334402916925, 63: 0.333751463513, 64: 0.333640470509, 65: 0.333336916937,\n    66: 0.333335272740, 67: 0.333333334757, 68: 0.333333333333, 69: 0.333333333333, 70: 0.333333333333,\n    71: 0.333333333333, 72: 0.333333333333, 73: 0.333333333333, 74: 0.330188535462, 75: 0.328463195587,\n    76: 0.328103961523, 77: 0.327686179352, 78: 0.327127029954, 79: 0.325989557839, 80: 0.325477474624,\n    81: 0.324944915351, 82: 0.324515222750, 83: 0.324267611367, 84: 0.323352310612, 85: 0.322630021300,\n    86: 0.322291776780, 87: 0.321993210806, 88: 0.321633376699, 89: 0.321134135786, 90: 0.320375745486,\n    91: 0.319902117697, 92: 0.319878254807, 93: 0.319097564988, 94: 0.318540916767, 95: 0.318094531790,\n    96: 0.317846446572, 97: 0.317806124732, 98: 0.317259497574, 99: 0.316526861740, 100: 0.315810476213,\n    101: 0.315538647721, 102: 0.314679637055, 103: 0.314060961473, 104: 0.313931077920, 105: 0.313606041188,\n    106: 0.313572397093, 107: 0.313569796325, 108: 0.313295987913, 109: 0.313103958893, 110: 0.312870732250,\n    111: 0.312817015081, 112: 0.312795668403, 113: 0.312781427608, 114: 0.312544838678, 115: 0.312153061267,\n    116: 0.310079114376, 117: 0.309963919957, 118: 0.309616161998, 119: 0.309576450296, 120: 0.309441272408,\n    121: 0.309267658509, 122: 0.307917673798, 123: 0.307608006706, 124: 0.307293322810, 125: 0.306890015254,\n    126: 0.306871518038, 127: 0.306221600984, 128: 0.304661694926, 129: 0.303829998236, 130: 0.303505330121,\n    131: 0.302688259886, 132: 0.302462825282, 133: 0.302319479063, 134: 0.302149661953, 135: 0.301841454005,\n    136: 0.301356344772, 137: 0.300235310856, 138: 0.299820133413, 139: 0.299489149586, 140: 0.299304260533,\n    141: 0.299077642337, 142: 0.298759871737, 143: 0.298355337567, 144: 0.298119952070, 145: 0.297851157208,\n    146: 0.297526134391, 147: 0.297119526038, 148: 0.296849270332, 149: 0.296717877521, 150: 0.296636591653,\n    151: 0.296495826266, 152: 0.296246488420, 153: 0.296167539660, 154: 0.296015918762, 155: 0.295977908435,\n    156: 0.295798805346, 157: 0.295547380439, 158: 0.295073392153, 159: 0.294790672783, 160: 0.294670135852,\n    161: 0.294581713908, 162: 0.294456424752, 163: 0.294344516307, 164: 0.294284159557, 165: 0.294025791982,\n    166: 0.293908273552, 167: 0.293759963742, 168: 0.293330950075, 169: 0.292796314564, 170: 0.292209170055,\n    171: 0.291832817449, 172: 0.291405472557, 173: 0.290868004162, 174: 0.289915170781, 175: 0.289576920225,\n    176: 0.289258242540, 177: 0.289023158672, 178: 0.288756641564, 179: 0.288429136611, 180: 0.288242166069,\n    181: 0.288155344057, 182: 0.288016105062, 183: 0.287832966608, 184: 0.287665271463, 185: 0.287509279762,\n    186: 0.287369711287, 187: 0.287103263276, 188: 0.286829421287, 189: 0.286640932516, 190: 0.286473776571,\n    191: 0.286340577759, 192: 0.286070175183, 193: 0.285651308543, 194: 0.285397771447, 195: 0.285133365064,\n    196: 0.284897792886, 197: 0.284700069348, 198: 0.284379917368, 199: 0.284122844342, 200: 0.283702018141,\n    201: 0.283455314336, 202: 0.283283874420, 203: 0.283043865651, 204: 0.282830317280, 205: 0.282786244819,\n    206: 0.282618572896, 207: 0.282433995546, 208: 0.282271233004, 209: 0.281947417233, 210: 0.281751793347,\n    211: 0.281633666679, 212: 0.281490480119, 213: 0.281339486835, 214: 0.281198166869, 215: 0.281028131802,\n    216: 0.280939271573, 217: 0.280823540966, 218: 0.280732736274, 219: 0.280582211168, 220: 0.280401547028,\n    221: 0.280286956860, 222: 0.280203665388, 223: 0.280089845048, 224: 0.279950621956, 225: 0.279880994743,\n    226: 0.279821068505, 227: 0.279772499820, 228: 0.279699803501, 229: 0.279607788988, 230: 0.279517026256,\n    231: 0.279441130466, 232: 0.279303928235, 233: 0.279236171502, 234: 0.279148980299, 235: 0.279089312763,\n    236: 0.279002312986, 237: 0.278903744629, 238: 0.278827506536, 239: 0.278756222904, 240: 0.278681098274,\n    241: 0.278610728879, 242: 0.278583384101, 243: 0.278505207393, 244: 0.278432011945, 245: 0.278349095984,\n    246: 0.278253395299, 247: 0.278194423531, 248: 0.278109869990, 249: 0.278038853233, 250: 0.277947626112,\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\"hsp6|{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 = 6\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"}}