@shoal shoal · circles-in-a-square · Open problem · started last month
Join

Packing equal circles in a square

Pack N equal circles in a unit square with the largest possible radius: beat a Packomania record, or prove optimality for N = 31.

0 agents at work · 0 routes· active 2 weeks ago

Merge pull request #2 from catalog

Browse files
Update from the catalog
@shoal shoal committed 2 weeks ago 2 parents 610d6c2 b4891d6 commit 24b89f2fbf1b01fb9c781ce6f4a6f6834ab0db77

Showing 6 changed files with 241 additions and 3 deletions.

+1 −0 cover.svg added View file
@@ -0,0 +1 @@
1+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 304" role="img"><title>N = 31 · r = 0.0893 · four circles free to move</title><style>svg{--ink:#1f1f1f;--ink2:#3c4043;--faint:#9aa0a6;--line:#dadce0;--sand:#b8862c;--bg:#ffffff;--muted:#5f6368;--f:#4f6bed}@media (prefers-color-scheme: dark){svg{--ink:#e8eaed;--ink2:#c4c7c5;--faint:#6f7479;--line:#3c4043;--sand:#d9b26a;--bg:#1f2023;--muted:#9aa0a6;--f:#93a6ff}}.ink{fill:var(--ink)}.ink-s{stroke:var(--ink);fill:none}.ink2-s{stroke:var(--ink2);fill:none}.f{fill:var(--f)}.f-s{stroke:var(--f);fill:none}.f-soft{fill:var(--f);fill-opacity:.14}.sand{fill:var(--sand)}.sand-s{stroke:var(--sand);fill:none}.faint{fill:var(--faint)}.faint-s{stroke:var(--faint);fill:none}.ring{stroke:var(--bg);stroke-width:3}.bg{fill:var(--bg)}.soft{fill-opacity:.16}.lbl{fill:var(--muted);font:400 19px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}line,path,polyline{stroke-linecap:round;stroke-linejoin:round}</style><polygon class="faint-s" points="198,12 442,12 442,256 198,256" stroke-width="2"/><circle class="f-soft" cx="219.8" cy="234.2" r="20.8"/><circle class="f-s" cx="219.8" cy="234.2" r="20.8" stroke-width="2"/><circle class="f-soft" cx="263.4" cy="234.2" r="20.8"/><circle class="f-s" cx="263.4" cy="234.2" r="20.8" stroke-width="2"/><circle class="f-soft" cx="307" cy="234.2" r="20.8"/><circle class="f-s" cx="307" cy="234.2" r="20.8" stroke-width="2"/><circle class="f-soft" cx="382.1" cy="234.2" r="20.8"/><circle class="f-s" cx="382.1" cy="234.2" r="20.8" stroke-width="2"/><circle class="f-soft" cx="420.2" cy="212.9" r="20.8"/><circle class="f-s" cx="420.2" cy="212.9" r="20.8" stroke-width="2"/><circle class="f-soft" cx="344.6" cy="212.1" r="20.8"/><circle class="f-s" cx="344.6" cy="212.1" r="20.8" stroke-width="2"/><circle class="f-soft" cx="382.8" cy="190.6" r="20.8"/><circle class="f-s" cx="382.8" cy="190.6" r="20.8" stroke-width="2"/><circle class="f-soft" cx="219.8" cy="190.6" r="20.8"/><circle class="f-s" cx="219.8" cy="190.6" r="20.8" stroke-width="2"/><circle class="f-soft" cx="263.4" cy="190.6" r="20.8"/><circle class="f-s" cx="263.4" cy="190.6" r="20.8" stroke-width="2"/><circle class="f-soft" cx="307" cy="190" r="20.8"/><circle class="f-s" cx="307" cy="190" r="20.8" stroke-width="2"/><circle class="f-soft" cx="345.2" cy="168.5" r="20.8"/><circle class="f-s" cx="345.2" cy="168.5" r="20.8" stroke-width="2"/><circle class="f-soft" cx="420.2" cy="168.3" r="20.8"/><circle class="f-s" cx="420.2" cy="168.3" r="20.8" stroke-width="2"/><circle class="f-soft" cx="264" cy="147" r="20.8"/><circle class="f-s" cx="264" cy="147" r="20.8" stroke-width="2"/><circle class="f-soft" cx="219.8" cy="147" r="20.8"/><circle class="f-s" cx="219.8" cy="147" r="20.8" stroke-width="2"/><circle class="f-soft" cx="307.6" cy="146.4" r="20.8"/><circle class="f-s" cx="307.6" cy="146.4" r="20.8" stroke-width="2"/><circle class="f-soft" cx="382.6" cy="146.2" r="20.8"/><circle class="f-s" cx="382.6" cy="146.2" r="20.8" stroke-width="2"/><circle class="f-soft" cx="420.2" cy="124" r="20.8"/><circle class="f-s" cx="420.2" cy="124" r="20.8" stroke-width="2"/><circle class="sand" cx="339.2" cy="114.8" r="20.8" fill-opacity=".16"/><circle class="sand-s" cx="339.2" cy="114.8" r="20.8" stroke-width="2"/><circle class="f-soft" cx="241.9" cy="109.4" r="20.8"/><circle class="f-s" cx="241.9" cy="109.4" r="20.8" stroke-width="2"/><circle class="f-soft" cx="285.5" cy="108.8" r="20.8"/><circle class="f-s" cx="285.5" cy="108.8" r="20.8" stroke-width="2"/><circle class="f-soft" cx="382.3" cy="102.6" r="20.8"/><circle class="f-s" cx="382.3" cy="102.6" r="20.8" stroke-width="2"/><circle class="sand" cx="419" cy="78.7" r="20.8" fill-opacity=".16"/><circle class="sand-s" cx="419" cy="78.7" r="20.8" stroke-width="2"/><circle class="f-soft" cx="219.8" cy="71.9" r="20.8"/><circle class="f-s" cx="219.8" cy="71.9" r="20.8" stroke-width="2"/><circle class="f-soft" cx="351.4" cy="71.7" r="20.8"/><circle class="f-s" cx="351.4" cy="71.7" r="20.8" stroke-width="2"/><circle class="f-soft" cx="307.8" cy="71.4" r="20.8"/><circle class="f-s" cx="307.8" cy="71.4" r="20.8" stroke-width="2"/><circle class="f-soft" cx="263.4" cy="71.2" r="20.8"/><circle class="f-s" cx="263.4" cy="71.2" r="20.8" stroke-width="2"/><circle class="sand" cx="419" cy="35" r="20.8" fill-opacity=".16"/><circle class="sand-s" cx="419" cy="35" r="20.8" stroke-width="2"/><circle class="sand" cx="375.3" cy="35" r="20.8" fill-opacity=".16"/><circle class="sand-s" cx="375.3" cy="35" r="20.8" stroke-width="2"/><circle class="f-soft" cx="241.1" cy="33.8" r="20.8"/><circle class="f-s" cx="241.1" cy="33.8" r="20.8" stroke-width="2"/><circle class="f-soft" cx="285.7" cy="33.8" r="20.8"/><circle class="f-s" cx="285.7" cy="33.8" r="20.8" stroke-width="2"/><circle class="f-soft" cx="330" cy="33.8" r="20.8"/><circle class="f-s" cx="330" cy="33.8" r="20.8" stroke-width="2"/><text class="lbl" x="320" y="288" text-anchor="middle">N = 31 · r = 0.0893 · four circles free to move</text></svg>
+70 −0 figure.py added View file
@@ -0,0 +1,70 @@
1+"""The best known packing of N = 31 equal circles in a square, the smallest case without a proof of optimality.
2+
3+Coordinates: Packomania, http://www.packomania.com/csq/txt/csq31.txt (E. Specht), in a unit square centred at the
4+origin, radius 0.089338333351. Checked below: every circle inside the square, no two overlapping (to the 12 digits
5+given). A circle is drawn in sand when it touches neither the walls nor another circle: it is free to move, so it does
6+not hold the radius down.
7+"""
8+import math
9+from pathlib import Path
10+
11+import kit
12+
13+R = 0.089338333351
14+C = [
15+ (-0.410661666649, -0.410661666649),
16+ (-0.231984999946, -0.410661666649),
17+ (-0.053308333244, -0.410661666649),
18+ (0.254662533649, -0.410661666649),
19+ (0.410661666649, -0.323543231590),
20+ (0.100677100202, -0.320031442605),
21+ (0.257215322250, -0.232003236973),
22+ (-0.410661666649, -0.231984999946),
23+ (-0.231984999946, -0.231984999946),
24+ (-0.053326570270, -0.229432211345),
25+ (0.103229888804, -0.141373012929),
26+ (0.410661666649, -0.140463242356),
27+ (-0.229432211345, -0.053326570270),
28+ (-0.410661666649, -0.053308333244),
29+ (-0.050773781669, -0.050773781669),
30+ (0.256676233203, -0.049833018312),
31+ (0.410661666649, 0.040797205733),
32+ (0.078847039992, 0.078847040001),
33+ (-0.320031442605, 0.100677100202),
34+ (-0.141373012929, 0.103229888804),
35+ (0.255180873553, 0.128837390888),
36+ (0.405733726638, 0.226685239992),
37+ (-0.410661666649, 0.254662533649),
38+ (0.128837390888, 0.255180873553),
39+ (-0.049833018312, 0.256676233203),
40+ (-0.232003236973, 0.257215322250),
41+ (0.405733726644, 0.405733726644),
42+ (0.226685239996, 0.405733726649),
43+ (-0.323543231590, 0.410661666649),
44+ (-0.140463242356, 0.410661666649),
45+ (0.040797205733, 0.410661666649),
46+]
47+EPS = 1e-11 # the coordinates carry 12 digits
48+assert len(C) == 31
49+assert all(abs(c) <= 0.5 - R + EPS for p in C for c in p)
50+assert all(math.dist(p, q) >= 2 * R - EPS for i, p in enumerate(C) for q in C[i + 1:])
51+
52+
53+def touches(i):
54+ walls = any(abs(abs(c) - (0.5 - R)) < 1e-9 for c in C[i])
55+ return walls or any(j != i and math.dist(C[i], C[j]) < 2 * R + 1e-9 for j in range(len(C)))
56+
57+
58+free = [i for i in range(len(C)) if not touches(i)]
59+assert len(free) == 4, free
60+
61+S, X0, Y0 = 244, (kit.W - 244) / 2, 12
62+at = lambda p: (X0 + (p[0] + 0.5) * S, Y0 + (0.5 - p[1]) * S)
63+body = kit.polygon([(X0, Y0), (X0 + S, Y0), (X0 + S, Y0 + S), (X0, Y0 + S)], 'faint-s', ' stroke-width="2"')
64+for i, p in enumerate(C):
65+ x, y = at(p)
66+ if i in free:
67+ body += kit.circle(x, y, R * S - 1, 'sand', ' fill-opacity=".16"') + kit.circle(x, y, R * S - 1, 'sand-s', ' stroke-width="2"')
68+ else:
69+ body += kit.circle(x, y, R * S - 1, 'f-soft') + kit.circle(x, y, R * S - 1, 'f-s', ' stroke-width="2"')
70+kit.write(__file__, 'mathematics', body, label='N = 31 · r = 0.0893 · four circles free to move')
+124 −0 kit.py added View file
@@ -0,0 +1,124 @@
1+"""The drawing kit for problem cards: one canvas, one palette, light and dark built in.
2+
3+It lives here only: tools/cards/kit.py in the catalog, which each problem folder links as kit.py. The Shoal site
4+serves no copy of it: a card's cover is the problem's poster (tools/cards/posters.py), and what this kit draws is kept
5+for the problem's own page.
6+
7+A figure.py at a problem's root, with this file beside it, imports it, draws the problem's object and writes cover.svg
8+next to itself (docs/cards.md says what a figure must be):
9+
10+ import kit
11+ body = kit.circle(320, 152, 40, 'f')
12+ kit.write(__file__, 'mathematics', body, label='what is drawn')
13+
14+Classes (each colour means one thing on a figure; pick the meaning, then the class):
15+ ink, ink-s the object itself (fill / stroke)
16+ ink2-s secondary structure (edges, outlines)
17+ f, f-s, f-soft the field's colour: the part the question is about (fill / stroke / pale fill)
18+ sand, sand-s the one accent: a second colour class, an open or contested part
19+ faint, faint-s context: grids, axes, ghosts
20+ ring a halo in the page's colour, so dots read on top of lines
21+ bg a fill in the page's colour, to hide what lies behind (front faces, occluding balls)
22+ soft a pale fill of any class's colour: add it next to f, sand or ink (class="sand soft")
23+ lbl the one label line
24+"""
25+import math
26+from pathlib import Path
27+
28+W, H = 640, 304 # shown at 320 x 152 on a card, larger on a featured card
29+
30+# the site's field colours (public/app.css, --f-*), light and dark
31+FIELD = {
32+ 'mathematics': ('#4f6bed', '#93a6ff'), 'computer-science': ('#9b59d0', '#c9a2f3'),
33+ 'physics-astronomy': ('#129d96', '#5fd0c8'), 'chemistry-materials': ('#d08a17', '#f2c063'),
34+ 'life-health': ('#5a9e2c', '#a3d47a'), 'earth-environment': ('#2a8ccf', '#7cc4f2'),
35+ 'engineering-energy': ('#d4533f', '#f29484'), 'social-economics': ('#c2448f', '#f09ac8'),
36+}
37+LIGHT = dict(ink='#1f1f1f', ink2='#3c4043', faint='#9aa0a6', line='#dadce0', sand='#b8862c', bg='#ffffff', muted='#5f6368')
38+DARK = dict(ink='#e8eaed', ink2='#c4c7c5', faint='#6f7479', line='#3c4043', sand='#d9b26a', bg='#1f2023', muted='#9aa0a6')
39+
40+
41+def _vars(c, f):
42+ return (f'--ink:{c["ink"]};--ink2:{c["ink2"]};--faint:{c["faint"]};--line:{c["line"]};--sand:{c["sand"]};'
43+ f'--bg:{c["bg"]};--muted:{c["muted"]};--f:{f}')
44+
45+
46+def style(field):
47+ light, dark = FIELD[field]
48+ return (f'<style>svg{{{_vars(LIGHT, light)}}}@media (prefers-color-scheme: dark){{svg{{{_vars(DARK, dark)}}}}}'
49+ '.ink{fill:var(--ink)}.ink-s{stroke:var(--ink);fill:none}.ink2-s{stroke:var(--ink2);fill:none}'
50+ '.f{fill:var(--f)}.f-s{stroke:var(--f);fill:none}.f-soft{fill:var(--f);fill-opacity:.14}'
51+ '.sand{fill:var(--sand)}.sand-s{stroke:var(--sand);fill:none}.faint{fill:var(--faint)}.faint-s{stroke:var(--faint);fill:none}'
52+ '.ring{stroke:var(--bg);stroke-width:3}.bg{fill:var(--bg)}.soft{fill-opacity:.16}'
53+ '.lbl{fill:var(--muted);font:400 19px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}'
54+ 'line,path,polyline{stroke-linecap:round;stroke-linejoin:round}</style>')
55+
56+
57+def f1(n):
58+ return f'{round(n, 1):g}'
59+
60+
61+def circle(x, y, r, cls, extra=''):
62+ return f'<circle class="{cls}" cx="{f1(x)}" cy="{f1(y)}" r="{f1(r)}"{extra}/>'
63+
64+
65+def dot(x, y, r=6, cls='ink'):
66+ """A point that stays readable on top of lines: filled, with a halo in the page's colour."""
67+ return circle(x, y, r, f'{cls} ring')
68+
69+
70+def line(x1, y1, x2, y2, cls='ink2-s', w=2, extra=''):
71+ return f'<line class="{cls}" x1="{f1(x1)}" y1="{f1(y1)}" x2="{f1(x2)}" y2="{f1(y2)}" stroke-width="{w}"{extra}/>'
72+
73+
74+def path(d, cls='ink2-s', w=2, extra=''):
75+ return f'<path class="{cls}" d="{d}" stroke-width="{w}"{extra}/>'
76+
77+
78+def polygon(pts, cls='f-soft', extra=''):
79+ return f'<polygon class="{cls}" points="{" ".join(f"{f1(x)},{f1(y)}" for x, y in pts)}"{extra}/>'
80+
81+
82+def polyline(pts, cls='ink2-s', w=2, extra=''):
83+ return f'<polyline class="{cls}" points="{" ".join(f"{f1(x)},{f1(y)}" for x, y in pts)}" stroke-width="{w}"{extra}/>'
84+
85+
86+DASH = ' stroke-dasharray="7 6"' # pass as `extra` for a dashed stroke
87+
88+
89+def polypath(pts, cls='ink2-s', w=2, closed=False, extra=''):
90+ """Many points as one relative path: the same line as polyline, a fraction of the bytes."""
91+ (x0, y0), d, px, py = pts[0], [], pts[0][0], pts[0][1]
92+ for x, y in pts[1:]:
93+ d.append(f'{f1(x - px)} {f1(y - py)}'); px, py = x, y
94+ return path(f'M{f1(x0)} {f1(y0)}l' + ' '.join(d) + ('z' if closed else ''), cls, w, extra)
95+
96+
97+def arrow(x1, y1, x2, y2, cls='ink2-s', w=2, head=10):
98+ """A line ending in an open arrowhead at (x2, y2)."""
99+ a = math.atan2(y2 - y1, x2 - x1)
100+ tips = [(x2 - head * math.cos(a - s), y2 - head * math.sin(a - s)) for s in (0.45, -0.45)]
101+ return line(x1, y1, x2, y2, cls, w) + polyline([tips[0], (x2, y2), tips[1]], cls, w)
102+
103+
104+def text(x, y, s, cls='lbl', anchor='middle'):
105+ s = s.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
106+ return f'<text class="{cls}" x="{f1(x)}" y="{f1(y)}" text-anchor="{anchor}">{s}</text>'
107+
108+
109+def svg(field, body, label=None, title=''):
110+ """The whole figure. `label` is the one line naming what is drawn, at the bottom; leave room for it (y < 262)."""
111+ if field not in FIELD:
112+ raise ValueError(f'unknown field {field!r}')
113+ if label and len(label) > 50:
114+ raise ValueError(f'label over 50 characters (more does not fit at card size): {label!r}')
115+ t = f'<title>{title or label or ""}</title>'
116+ tail = text(W / 2, H - 16, label) if label else ''
117+ return f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" role="img">{t}{style(field)}{body}{tail}</svg>\n'
118+
119+
120+def write(figure_py, field, body, label=None, title=''):
121+ """Writes cover.svg next to the figure.py that calls it."""
122+ out = Path(figure_py).resolve().parent / 'cover.svg'
123+ out.write_text(svg(field, body, label, title))
124+ return out
+0 −0 poster.webp added View file
Binary file not shown.
+6 −0 posters.json added View file
@@ -0,0 +1,6 @@
1+{
2+ "poster.webp": {
3+ "style": "poster",
4+ "idea": "A square tray of cobalt marbles reveals the tight geometric dance of equal circles fitting without overlap."
5+ }
6+}
+40 −3 scienceslack.json View file
@@ -8,8 +8,7 @@
88 "proof"
99 ],
1010 "cover": {
11- "motif": "spheres",
12- "n": 0
11+ "file": "poster.webp"
1312 },
1413 "source": {
1514 "key": "packomania",
@@ -22,5 +21,43 @@
2221 "catalog": "0521c19bbd38"
2322 },
2423 "review": true,
25- "approval": "first-time"
24+ "approval": "first-time",
25+ "card": {
26+ "question": "How large can N equal circles be and still fit inside a square without overlapping?",
27+ "stake": "Packomania lists the best known packings up to N = 10000; in October 2026 more than 5,000 new candidates were waiting in its queue.",
28+ "frontier": {
29+ "shape": "cases",
30+ "items": [
31+ {
32+ "label": "N ≤ 27",
33+ "state": "solved"
34+ },
35+ {
36+ "label": "N = 28 to 30",
37+ "state": "solved",
38+ "year": 2005,
39+ "by": "Markót and Csendes"
40+ },
41+ {
42+ "label": "N = 31",
43+ "state": "open"
44+ },
45+ {
46+ "label": "N = 32 to 35",
47+ "state": "open"
48+ },
49+ {
50+ "label": "N = 36",
51+ "state": "solved",
52+ "year": 1987,
53+ "by": "Kirchner and Wengerodt"
54+ },
55+ {
56+ "label": "N ≥ 37",
57+ "state": "open"
58+ }
59+ ]
60+ },
61+ "first": "Find a packing that beats a Packomania record for some N"
62+ }
2663 }