There Are Magic Hexagons of Every Order
There Are Magic Hexagons of Every Order
每一阶都有神奇的六角幻方
What is so special about the number 19? The question came up last month in a conversation among YSDA alumni, when the school turned 19. Someone pointed out that 19 is a twin prime. Someone else replied that 19 is the number of cells in the only non-trivial normal magic hexagon. Wait, what is a “magic hexagon”? Let us start there. 数字 19 有什么特别之处?上个月在 YSDA 校友的一次谈话中,当学校迎来 19 周年校庆时,这个问题被提了出来。有人指出 19 是孪生素数,另一个人则回答说,19 是唯一一个非平凡的“标准幻六角形”中的单元格数量。等等,什么是“幻六角形”?让我们从这里开始。
Magic Squares and Magic Hexagons
幻方与幻六角形
You probably know about magic squares. A magic square is a square grid of numbers in which every row, every column, and both main diagonals add up to the same total, known as the magic constant. We also usually require the numbers to be consecutive - typically from $1$ to $n^2$ - and call it a normal magic square. Otherwise, we could simply put the same number into every cell, which would be a very boring way to fill a square. Magic squares have been known for millennia and are now very well understood. We have algorithms for constructing normal magic squares of every order $n>2$. 你可能听说过幻方。幻方是一个数字方阵,其中每一行、每一列以及两条主对角线的数字之和都相等,这个和被称为幻和。我们通常还要求这些数字是连续的——通常是从 $1$ 到 $n^2$——并称之为标准幻方。否则,我们只需在每个单元格中填入相同的数字,那将是一种非常无聊的填法。幻方已经存在了几千年,现在人们对它已经非常了解。我们拥有构建任意阶数 $n>2$ 的标准幻方的算法。
A magic hexagon applies the same idea to a hexagonal grid. Its cells form straight lines in three directions, and every such line must have the same sum. As with squares, a magic hexagon is called normal if it contains the consecutive numbers from $1$ to $3n^2-3n+1$, the total number of cells in a hexagon of order $n$. Above you can see the only non-trivial normal magic hexagon in existence - apart from its own rotations and reflections. 幻六角形将同样的理念应用于六角形网格。它的单元格在三个方向上形成直线,且每一条直线必须具有相同的和。与幻方一样,如果一个幻六角形包含从 $1$ 到 $3n^2-3n+1$(即 $n$ 阶六角形的总单元格数)的连续数字,它就被称为标准幻六角形。在上方,你可以看到现存唯一一个非平凡的标准幻六角形(不计其自身的旋转和镜像)。
The proof is straightforward. In each of the three directions, the cells are partitioned into $2n-1$ lines. Therefore, the sum of all the numbers must be divisible by $2n-1$. For every order $n>3$, the sum of the numbers from $1$ to $3n^2-3n+1$ fails this divisibility test. Well, ending the story here would be no fun. To make things more interesting, let’s look at the so-called abnormal magic hexagons. Here we relax one constraint: the numbers on the grid must still be consecutive, but they no longer have to start at $1$. 证明过程很简单。在三个方向中的每一个方向上,单元格被划分为 $2n-1$ 条线。因此,所有数字的总和必须能被 $2n-1$ 整除。对于所有 $n>3$ 的阶数,从 $1$ 到 $3n^2-3n+1$ 的数字之和无法通过这一整除性测试。当然,故事到此结束就太没意思了。为了让事情更有趣,让我们看看所谓的“非标准幻六角形”。在这里,我们放宽了一个限制:网格上的数字必须仍然是连续的,但它们不再必须从 $1$ 开始。
This small relaxation suddenly allows new solutions to appear. Finding them, however, is not easy. Unlike with magic squares, there was no formulaic construction or deterministic algorithm. The only known approach was to wander through a brutally large search space of possible arrangements. According to Wikipedia, as of July 2026, the largest known solution was a hexagon of order $n=9$, found by Klaus Meffert in 2024. So… what makes these solutions so hard to find? And how about we try? 这种微小的放宽突然让新的解法得以出现。然而,找到它们并不容易。与幻方不同,这里没有公式化的构造或确定性算法。唯一已知的途径是在极其庞大的可能排列搜索空间中进行探索。据维基百科记载,截至 2026 年 7 月,已知最大的解是 Klaus Meffert 在 2024 年发现的 $n=9$ 阶六角形。那么……是什么让这些解如此难以寻找?我们要不要试一试?
Chapter 1: Making Observations (With Human Brain)
第一章:观察(利用人类大脑)
There is a clear tension between two independent constraints: The numbers must be consecutive; All line sums must be equal, even though the lines have different lengths. The prior solutions I found suggested that people had already tried several search algorithms and likely optimized them well. That made me think that, if I wanted to advance the field, I should focus not on making the search faster, but on making the search space smaller. 在两个独立的约束之间存在明显的张力:数字必须是连续的;所有直线的和必须相等,尽管这些直线的长度各不相同。我发现之前的解法表明,人们已经尝试了几种搜索算法,并且很可能已经对其进行了很好的优化。这让我想到,如果我想推动这一领域的发展,我不应该专注于加快搜索速度,而应该专注于缩小搜索空间。
Observation: Antisymmetric hexagons are much simpler 观察:反对称六角形要简单得多
First, let’s restrict the numbers on the grid to the symmetric interval $-K,\ldots,K$ for some $K$. If all line sums are equal, this is equivalent to requiring that every line sum be zero. Second, put $0$ in the center and require that cells opposite each other under a 180-degree rotation contain opposite values. If one cell contains $x$, its antipodal cell contains $-x$. Notice how many constraints disappear. Every line through the center sums to zero automatically because its values cancel in opposite pairs. Every other line has an antipodal line with the sum of antipodal opposite numbers. If one of them sums to zero, so does the other. 首先,让我们将网格上的数字限制在某个 $K$ 的对称区间 $-K,\ldots,K$ 内。如果所有直线的和相等,这就等同于要求每一条直线的和为零。其次,将 $0$ 放在中心,并要求 180 度旋转后相对的单元格包含相反的值。如果一个单元格包含 $x$,其对径单元格就包含 $-x$。注意有多少约束消失了。每一条穿过中心的直线其和自动为零,因为它们的值在对径对中相互抵消。每一条其他直线都有对应的对径直线,其和由对径的相反数组成。如果其中一条和为零,另一条也必然为零。
Of course, simplifying the constraints introduces a risk: perhaps no solutions satisfy the extra symmetry at all. At this point, antisymmetry was simply a plausible place to search, following the drunkard’s principle. But once I started thinking about zero-sum hexagons, another structure appeared. 当然,简化约束引入了一个风险:也许根本没有任何解满足这种额外的对称性。在这一点上,反对称性只是遵循“酒鬼原则”(在路灯下找钥匙)的一个合理的搜索切入点。但一旦我开始思考零和六角形,另一种结构就出现了。
Observation: Every zero-sum hexagon is built from the same 6-point ring 观察:每个零和六角形都是由同一个 6 点环构建的
Consider any hexagonal grid, zero-sum or not. Take the six cells surrounding any interior point and add the alternating pattern $[-1,+1,-1,+1,-1,+1].$ Leave the central cell unchanged. Every straight line that intersects this ring receives either no contribution or two opposite contributions, $+1$ and $-1$. Its sum therefore remains unchanged. We can add any multiple of this pattern without changing a single line sum. 考虑任何六角形网格,无论是否为零和。取围绕任何内部点的六个单元格,并加上交替模式 $[-1,+1,-1,+1,-1,+1]$。保持中心单元格不变。每一条穿过这个环的直线要么没有贡献,要么得到两个相反的贡献 $+1$ 和 $-1$。因此,它的和保持不变。我们可以添加该模式的任何倍数,而不会改变任何一条直线的和。
These local alternating rings form a basis: every zero-sum hexagon can be built as a unique linear combination of them. I will omit the proof for brevity, but the idea is fairly straightforward. Starting at the outer layer, choose ring coefficients that cancel its cells, then peel the layer away and continue inward by induction. 这些局部交替环构成了一个基:每个零和六角形都可以作为它们的唯一线性组合来构建。为了简洁起见,我将省略证明,但这个想法相当直观。从外层开始,选择能抵消其单元格的环系数,然后剥离该层,并通过归纳法向内继续。
An order-$n$ zero-sum hexagon therefore has two equivalent representations: its visible cell values; an order-$(n-1)$ potential field, recording how much of each local ring it contains. The potential field representation also satisfies every line-sum constraint by construction. It does not, however, guarantee that the visible values are distinct and consecutive. Those remain difficult global constraints. 因此,$n$ 阶零和六角形有两种等价的表示形式:其可见的单元格值;以及一个 $(n-1)$ 阶势场,记录它包含每个局部环的程度。势场表示法在构造上满足了每一条直线的和约束。然而,它并不能保证可见的数值是不同且连续的。这些仍然是困难的全局约束。
Chapter 2: Finding New Hexagons (AI Writes Code)
第二章:寻找新的六角形(AI 编写代码)
Around the same time, I had been helping to pre-solve problems for the Midni… 与此同时,我一直在协助预解 Midni… 的问题。