{"id":"circle-packing-pentagon","name":"Equal circles in a regular pentagon","family":"combinatorics","description":"Place n circles in the regular pentagon 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 pentagon\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 pentagon 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 `cpt`, 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-pentagon. Prints one JSON line: {\"metric\": record_ratio, ...}.\n\nGenerated by tools/packomania_import.py from https://packomania.com/cpt/cpt.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 pentagon with circumradius 1 centred at the origin. Source: Packomania (E. Specht),\n# https://packomania.com/cpt/cpt.html, fetched 2026-09-06. only small n are proven.\nRECORDS = {\n    1: 0.809016994375, 2: 0.437152698242, 3: 0.389795792433, 4: 0.354680462504, 5: 0.340440645254,\n    6: 0.309016994375, 7: 0.277511095117, 8: 0.257541824500, 9: 0.243640224399, 10: 0.230721507966,\n    11: 0.224333593340, 12: 0.217384640521, 13: 0.207999994722, 14: 0.202386816023, 15: 0.197735768366,\n    16: 0.191785609135, 17: 0.183126736787, 18: 0.178473321196, 19: 0.173441904330, 20: 0.169279411749,\n    21: 0.165404018640, 22: 0.161673301786, 23: 0.158923367389, 24: 0.156027298450, 25: 0.153122210789,\n    26: 0.150683336700, 27: 0.148137584795, 28: 0.145444423784, 29: 0.143333013135, 30: 0.141698173815,\n    31: 0.138616362210, 32: 0.135793611068, 33: 0.134134799538, 34: 0.131960534658, 35: 0.130170592942,\n    36: 0.128215138245, 37: 0.126679668746, 38: 0.125056798044, 39: 0.124185741467, 40: 0.122413791780,\n    41: 0.120982726955, 42: 0.119848964213, 43: 0.118421345534, 44: 0.117257562843, 45: 0.115792923917,\n    46: 0.114685668831, 47: 0.113728619203, 48: 0.112997340346, 49: 0.111299134462, 50: 0.110419276505,\n    51: 0.108971323158, 52: 0.107852412844, 53: 0.106722676369, 54: 0.105895776586, 55: 0.104863207018,\n    56: 0.104252745744, 57: 0.103187535998, 58: 0.102435670827, 59: 0.101468332217, 60: 0.100739761056,\n    61: 0.099859697138, 62: 0.099194901497, 63: 0.098454910555, 64: 0.097834421788, 65: 0.097013439104,\n    66: 0.096256109964, 67: 0.095785092097, 68: 0.095077744308, 69: 0.094438906523, 70: 0.093736337552,\n    71: 0.093001827819, 72: 0.092405877836, 73: 0.091856585595, 74: 0.091081045227, 75: 0.090526425533,\n    76: 0.089885244874, 77: 0.089275764804, 78: 0.088753888691, 79: 0.088155608032, 80: 0.087759391988,\n    81: 0.087256528187, 82: 0.086531018480, 83: 0.086062502187, 84: 0.085582245062, 85: 0.085105640203,\n    86: 0.084693665494, 87: 0.084353558917, 88: 0.083957834537, 89: 0.083373984546, 90: 0.082916317197,\n    91: 0.082486675079, 92: 0.082097116118, 93: 0.081604858730, 94: 0.081226027424, 95: 0.080767780940,\n    96: 0.080301040266, 97: 0.079943232591, 98: 0.079605103982, 99: 0.079303089608, 100: 0.078846720977,\n    101: 0.078397075020, 102: 0.078049093952, 103: 0.077631543326, 104: 0.077168830932, 105: 0.076787199063,\n    106: 0.076515935706, 107: 0.076149393401, 108: 0.075754999505, 109: 0.075483429846, 110: 0.075131105447,\n    111: 0.074877167713, 112: 0.074526781472, 113: 0.074290113999, 114: 0.073964717970, 115: 0.073627370472,\n    116: 0.073329299010, 117: 0.072993462481, 118: 0.072709457058, 119: 0.072392698136, 120: 0.072129502864,\n    121: 0.071828527609, 122: 0.071564375957, 123: 0.071264314128, 124: 0.070978271129, 125: 0.070710600803,\n    126: 0.070440622682, 127: 0.070211417946, 128: 0.069935399593, 129: 0.069729464282, 130: 0.069387326253,\n    131: 0.069105802355, 132: 0.068829497993, 133: 0.068582227196, 134: 0.068261352367, 135: 0.068040648959,\n    136: 0.067765039748, 137: 0.067545701581, 138: 0.067338459371, 139: 0.067090550524, 140: 0.066864948010,\n    141: 0.066699596393, 142: 0.066470805976, 143: 0.066176694705, 144: 0.065970110319, 145: 0.065781819983,\n    146: 0.065569457672, 147: 0.065412400035, 148: 0.065149259364, 149: 0.064960070341, 150: 0.064730870089,\n    151: 0.064486188449, 152: 0.064303447765, 153: 0.064104138705, 154: 0.063934247315, 155: 0.063792464324,\n    156: 0.063543880700, 157: 0.063378537105, 158: 0.063128021010, 159: 0.062943785355, 160: 0.062737965620,\n    161: 0.062534800211, 162: 0.062329247848, 163: 0.062130345361, 164: 0.061963172335, 165: 0.061769355491,\n    166: 0.061559614133, 167: 0.061377202938, 168: 0.061197868747, 169: 0.061039784632, 170: 0.060870040510,\n    171: 0.060703446559, 172: 0.060508367506, 173: 0.060356303309, 174: 0.060201479446, 175: 0.060015243635,\n    176: 0.059846499713, 177: 0.059661881434, 178: 0.059505580185, 179: 0.059361397555, 180: 0.059217781153,\n    181: 0.059099157200, 182: 0.058908887350, 183: 0.058783353045, 184: 0.058597882648, 185: 0.058444798229,\n    186: 0.058291372929, 187: 0.058148151436, 188: 0.058011965909, 189: 0.057887757934, 190: 0.057732101738,\n    191: 0.057580382406, 192: 0.057450429294, 193: 0.057312414847, 194: 0.057135549328, 195: 0.056983864053,\n    196: 0.056820122561, 197: 0.056676656007, 198: 0.056537340893, 199: 0.056408547824, 200: 0.056271364514,\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 / 5) - c[0] * math.cos((2 * j + 1) * math.pi / 5) - c[1] * math.sin((2 * j + 1) * math.pi / 5) for j in range(5))\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\"cpt|{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 / 5) - c[0] * math.cos((2 * j + 1) * math.pi / 5) - c[1] * math.sin((2 * j + 1) * math.pi / 5) for j in range(5))\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"}}