{"id":"circle-packing-hexadecagon","name":"Equal circles in a regular hexadecagon","family":"combinatorics","description":"Place n circles in the regular hexadecagon with circumradius 1 centred at the origin 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 circles in a regular hexadecagon\n\n## Goal\n\n`pack.py` exposes `pack(n: int, time_budget: float, seed: int) -> list[tuple[float, ...]]`: the\ncentres of `n` circles inside the regular hexadecagon with circumradius 1 centred at the origin (2 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 = 8, 13, 19, 26, 31, 37, 44, 52, 68, 85, 101, 120, 150, 200`, 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 `cxd`, 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 200) 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 circle-packing-hexadecagon. Prints one JSON line: {\"metric\": record_ratio, ...}.\n\nGenerated by tools/packomania_import.py from https://packomania.com/cxd/cxd.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 \"8,13,19,26,31,37,44,52,68,85,101,120,150,200\")\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\", \"8,13,19,26,31,37,44,52,68,85,101,120,150,200\").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 = 2\n\n# Best-known values: equal objects in the regular hexadecagon with circumradius 1 centred at the origin. Source: Packomania (E. Specht),\n# https://packomania.com/cxd/cxd.html, fetched 2026-09-06. only small n are proven.\nRECORDS = {\n    1: 0.980785280403, 2: 0.495149721732, 3: 0.457221451812, 4: 0.410879308247, 5: 0.364795992040,\n    6: 0.331170661062, 7: 0.327408427053, 8: 0.298219404666, 9: 0.275276047043, 10: 0.259076416136,\n    11: 0.251164419238, 12: 0.244950583610, 13: 0.232797378030, 14: 0.228751748884, 15: 0.218093322591,\n    16: 0.213661979610, 17: 0.205917004872, 18: 0.202733212758, 19: 0.202115798420, 20: 0.192692071372,\n    21: 0.188035399172, 22: 0.181548742791, 23: 0.178389000729, 24: 0.175006175983, 25: 0.172287084916,\n    26: 0.169380978228, 27: 0.167333899680, 28: 0.165343666369, 29: 0.162161216251, 30: 0.160554722034,\n    31: 0.156347782078, 32: 0.153818259145, 33: 0.152117848281, 34: 0.149199102273, 35: 0.147680248230,\n    36: 0.146379246751, 37: 0.145538331458, 38: 0.141827451649, 39: 0.139984857939, 40: 0.138529233057,\n    41: 0.136082978898, 42: 0.134590794263, 43: 0.133206771660, 44: 0.131782751937, 45: 0.130457611226,\n    46: 0.129031520707, 47: 0.127965573608, 48: 0.126752861782, 49: 0.125224583493, 50: 0.124309646840,\n    51: 0.123031513986, 52: 0.122093713681, 53: 0.120820011984, 54: 0.120295059310, 55: 0.119615478307,\n    56: 0.117825103758, 57: 0.116957820523, 58: 0.115827982443, 59: 0.114878920879, 60: 0.114145934146,\n    61: 0.113537399228, 62: 0.111906704129, 63: 0.111131002358, 64: 0.110143534712, 65: 0.109509650513,\n    66: 0.108787930470, 67: 0.107858486148, 68: 0.107112259286, 69: 0.106390898460, 70: 0.105736301152,\n    71: 0.105065645006, 72: 0.104379962641, 73: 0.103882738142, 74: 0.103431779611, 75: 0.102347738100,\n    76: 0.101651605712, 77: 0.100969657337, 78: 0.100435949876, 79: 0.099735335856, 80: 0.099261921501,\n    81: 0.098809547404, 82: 0.098387825085, 83: 0.098019112369, 84: 0.097495551199, 85: 0.096800013134,\n    86: 0.095884090091, 87: 0.095255981179, 88: 0.094621460822, 89: 0.094136751728, 90: 0.093630994308,\n    91: 0.093121125226, 92: 0.092636810667, 93: 0.092274065221, 94: 0.091745732828, 95: 0.091292035235,\n    96: 0.090816942618, 97: 0.090384196570, 98: 0.089997526545, 99: 0.089677133347, 100: 0.089221530647,\n    101: 0.088715610784, 102: 0.088230728413, 103: 0.087830356054, 104: 0.087426745495, 105: 0.087098806284,\n    106: 0.086743164698, 107: 0.086264110555, 108: 0.085814904455, 109: 0.085328022973, 110: 0.085050962448,\n    111: 0.084657408389, 112: 0.084435175294, 113: 0.084015455037, 114: 0.083719221135, 115: 0.083388430929,\n    116: 0.083069337897, 117: 0.082767795280, 118: 0.082450799752, 119: 0.082131453570, 120: 0.081724687498,\n    121: 0.081251525979, 122: 0.080858850073, 123: 0.080425361133, 124: 0.080154293197, 125: 0.079846836187,\n    126: 0.079563197380, 127: 0.079316216763, 128: 0.079095241745, 129: 0.078777049136, 130: 0.078475072721,\n    131: 0.078131215128, 132: 0.077844501567, 133: 0.077593823549, 134: 0.077365638225, 135: 0.077124729924,\n    136: 0.076827882410, 137: 0.076522500411, 138: 0.076244458501, 139: 0.075957199993, 140: 0.075699064836,\n    141: 0.075352995070, 142: 0.075127057404, 143: 0.074886459294, 144: 0.074620428867, 145: 0.074365483672,\n    146: 0.074093279496, 147: 0.073898179895, 148: 0.073678029750, 149: 0.073508311497, 150: 0.073262079353,\n    151: 0.073119798077, 152: 0.072819765466, 153: 0.072600658662, 154: 0.072377972560, 155: 0.072169287700,\n    156: 0.071962743253, 157: 0.071715869764, 158: 0.071510406284, 159: 0.071195045875, 160: 0.070967240176,\n    161: 0.070714453092, 162: 0.070423466029, 163: 0.070220540427, 164: 0.070116122236, 165: 0.069856303698,\n    166: 0.069684721845, 167: 0.069504844014, 168: 0.069316361498, 169: 0.069108833251, 170: 0.068917196448,\n    171: 0.068770090929, 172: 0.068556705334, 173: 0.068333866674, 174: 0.068146835518, 175: 0.067956361957,\n    176: 0.067812444407, 177: 0.067628984365, 178: 0.067484198183, 179: 0.067278582384, 180: 0.067096821787,\n    181: 0.066957149681, 182: 0.066809709984, 183: 0.066599490025, 184: 0.066311677918, 185: 0.066114478754,\n    186: 0.065970327268, 187: 0.065822217091, 188: 0.065627506828, 189: 0.065542183360, 190: 0.065405175062,\n    191: 0.065274502055, 192: 0.065079422726, 193: 0.064933261714, 194: 0.064767602229, 195: 0.064583911559,\n    196: 0.064403713427, 197: 0.064261143761, 198: 0.064087420987, 199: 0.063985436301, 200: 0.063775074264,\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 min(1.0 * math.cos(math.pi / 16) - c[0] * math.cos((2 * j + 1) * math.pi / 16) - c[1] * math.sin((2 * j + 1) * math.pi / 16) for j in range(16))\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\"cxd|{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 = 2\n\n\ndef _boundary(c):\n    return min(1.0 * math.cos(math.pi / 16) - c[0] * math.cos((2 * j + 1) * math.pi / 16) - c[1] * math.sin((2 * j + 1) * math.pi / 16) for j in range(16))\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"}}