{"id":"circle-packing-circle-radii-n","name":"Circles with radii i in a circle","family":"combinatorics","description":"Place n circles in the unit disk (radius 1) as large as possible (r_i = (i) · s). 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":"# Circles with radii i in a circle\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 unit disk (radius 1) (2 coordinates each). Object `i` (1-based) has radius `((i) · s)`, where the eval derives the largest feasible scale `s`; the score is the largest object's radius.\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 `ccin`, 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 2000) 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-circle-radii-n. Prints one JSON line: {\"metric\": record_ratio, ...}.\n\nGenerated by tools/packomania_import.py from https://packomania.com/ccin/ccin.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 = 2\n\n# Best-known values: r_i = (i) · s objects in the unit disk (radius 1). Source: Packomania (E. Specht),\n# https://packomania.com/ccin/ccin.html, fetched 2026-09-06. only small n are proven.\nRECORDS = {\n    1: 1.000000000000, 2: 0.666666666667, 3: 0.600000000000, 4: 0.571428571429, 5: 0.555469288333,\n    6: 0.542640687119, 7: 0.519977897050, 8: 0.493165141801, 9: 0.467941000492, 10: 0.454541466714,\n    11: 0.440693929196, 12: 0.422961308500, 13: 0.412098358012, 14: 0.398909868871, 15: 0.386219726423,\n    16: 0.376841964345, 17: 0.367239298376, 18: 0.359139769580, 19: 0.350293089177, 20: 0.342462425681,\n    21: 0.335683774638, 22: 0.329537232966, 23: 0.323036150563, 24: 0.316835269443, 25: 0.311387317984,\n    26: 0.305960855061, 27: 0.300832427789, 28: 0.296215183171, 29: 0.291506764758, 30: 0.286970495601,\n    31: 0.282771273549, 32: 0.278746094616, 33: 0.274849612282, 34: 0.271203877318, 35: 0.267483732649,\n    36: 0.264107928757, 37: 0.260960824666, 38: 0.257710780360, 39: 0.254569617068, 40: 0.251644994145,\n    41: 0.248777002525, 42: 0.246048849401, 43: 0.243305345567, 44: 0.240736277435, 45: 0.238139377034,\n    46: 0.235651027882, 47: 0.233266603647, 48: 0.230990400294, 49: 0.228778537727, 50: 0.226690133360,\n    51: 0.224065624360, 52: 0.222003637260, 53: 0.219996300324, 54: 0.218152316295, 55: 0.216119453948,\n    56: 0.214219570324, 57: 0.212402732101, 58: 0.210789945656, 59: 0.209049231200, 60: 0.207583470150,\n    61: 0.205933088040, 62: 0.204170116877, 63: 0.202622167431, 64: 0.201116726300, 65: 0.199651070037,\n    66: 0.198262542330, 67: 0.196806455117, 68: 0.195409713982, 69: 0.194034910001, 70: 0.192862925372,\n    71: 0.191339205566, 72: 0.190100078662, 73: 0.188797898330, 74: 0.187652229447, 75: 0.186530049324,\n    76: 0.185357830183, 77: 0.184183912408, 78: 0.182959781717, 79: 0.181803788385, 80: 0.180797827391,\n    81: 0.179643777864, 82: 0.178719435871, 83: 0.177624417057, 84: 0.176580836418, 85: 0.175519993297,\n    86: 0.174561063816, 87: 0.173564143975, 88: 0.172608841845, 89: 0.171722472336, 90: 0.170842299992,\n    91: 0.169908154501, 92: 0.169048585789, 93: 0.168145184781, 94: 0.167269807352, 95: 0.166459135225,\n    96: 0.165564282566, 97: 0.164812382141, 99: 0.163202604980, 100: 0.162386149659, 101: 0.161571750169,\n    102: 0.160772055399, 103: 0.159938775645, 104: 0.159294159135, 105: 0.158557176990, 106: 0.157702337821,\n    107: 0.156974221138, 108: 0.156382455301, 109: 0.155668860503, 110: 0.154979545043, 111: 0.154296471241,\n    112: 0.153654173367, 113: 0.153137421641, 114: 0.152236214785, 115: 0.151681159211, 116: 0.151060666845,\n    117: 0.150453449066, 118: 0.149778960864, 119: 0.149184148617, 120: 0.148567956499, 121: 0.147886669501,\n    122: 0.147388947763, 123: 0.146821173141, 124: 0.146294678036, 125: 0.145664418945, 126: 0.145106446849,\n    127: 0.144514628994, 128: 0.144063986076, 129: 0.143480695276, 130: 0.142886243063, 131: 0.142377706518,\n    132: 0.141820353032, 133: 0.141326960604, 134: 0.140864777521, 135: 0.140356131481, 136: 0.139845123479,\n    137: 0.139326214815, 138: 0.138891118974, 139: 0.138333822180, 140: 0.137886863875, 141: 0.137347902807,\n    142: 0.136812397663, 143: 0.136456780567, 144: 0.136014323995, 145: 0.135501167812, 146: 0.135001784056,\n    147: 0.134604177751, 148: 0.134197078268, 149: 0.133721480741, 150: 0.133338593597, 151: 0.132872130339,\n    152: 0.132449133927, 153: 0.132000255400, 154: 0.131627906198, 155: 0.131257885457, 156: 0.130743269848,\n    157: 0.130391161493, 158: 0.129891996762, 159: 0.129583620644, 160: 0.129236802487, 161: 0.128789539180,\n    162: 0.128333050053, 163: 0.127996820672, 164: 0.127624131936, 165: 0.127188295103, 166: 0.126846718525,\n    167: 0.126421105571, 168: 0.126073666756, 169: 0.125748187366, 170: 0.125364168676, 171: 0.125064209148,\n    172: 0.124687714879, 173: 0.124307778649, 174: 0.123990417421, 175: 0.123668568186, 176: 0.123318516671,\n    177: 0.122911327712, 178: 0.122612039183, 179: 0.122287918906, 180: 0.121917829244, 181: 0.121637160801,\n    182: 0.121282230952, 183: 0.120945925383, 184: 0.120609137234, 185: 0.120344702362, 186: 0.120048886760,\n    187: 0.119650831277, 188: 0.119380739888, 189: 0.119036301390, 190: 0.118724525107, 191: 0.118402847864,\n    192: 0.118121994269, 193: 0.117808264268, 194: 0.117516113032, 195: 0.117259213228, 196: 0.116973039841,\n    197: 0.116656429526, 198: 0.116381763645, 199: 0.116075026825, 200: 0.115859964556, 300: 0.094723794939,\n    400: 0.082214020508, 600: 0.067286779611, 800: 0.058326432688, 1000: 0.052193175911, 2000: 0.036953992134,\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.hypot(c[0], c[1])\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 i\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\"ccin|{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 1.0 - math.hypot(c[0], c[1])\n\n\ndef _weight(i):\n    return i\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"}}