数字华容道(15-Puzzle)的规则简单到一句话就能说清:把打乱的 1 到 15 滑回顺序。但它藏着一个让无数人抓狂的秘密——随手打乱的棋盘,有整整一半根本拼不回去。这不是运气问题,而是一条优雅的数学定理。
一场 19 世纪的悬赏狂热
15-Puzzle 在 1880 年前后风靡欧美,掀起了一阵不亚于今天爆款手游的热潮。据说当时有人悬赏重金,征求把特定的"14-15 调换"局面还原的解法。无数人废寝忘食地尝试,却无一成功——因为那个局面,在数学上根本无解。悬赏者非常清楚这一点。
关键概念:逆序数
要理解为什么,我们需要一个叫"逆序数(inversions)"的概念。把棋盘上的数字(忽略空格)按从左到右、从上到下读成一个序列。如果一个较大的数字排在一个较小的数字前面,就算作一个"逆序"。
例如序列 2, 1, 3 里,2 排在 1 前面,这是 1 个逆序。把所有这样的数对都数一遍,就得到总逆序数。
魔法不变量
每滑动一次方块,会发生什么?横向滑动不改变数字的阅读顺序,逆序数不变。纵向滑动会让一个数字跨过 3 个数字,逆序数的奇偶性……经过仔细计算后,结合空格所在行的变化,可以证明一个量始终保持不变:逆序数的奇偶 + 空格所在行的奇偶,这个组合永远不变。
于是,一半的局面无解
已完成的目标状态对应一个确定的奇偶值。任何可以还原的打乱,都必须和它有相同的奇偶。而当你完全随机地打乱 15 个数字时,得到"正确奇偶"和"错误奇偶"的概率各占一半。错误奇偶的那一半,无论你怎么滑,都永远到不了终点。臭名昭著的"14-15 调换",正是把奇偶性恰好翻转了一次。
所以我们的华容道一定有解
正因如此,一个负责任的华容道游戏绝不能用"完全随机排列"来打乱——那样会有一半的局面坑害玩家。正确的做法是:从已经完成的状态出发,随机地走很多步合法的滑动。因为每一步合法滑动都不会破坏奇偶不变量,这样得到的局面必然可解。这正是昼夜工坊版本采用的方式——你遇到的每一局,都保证能还原。
顺手一提:上帝之数
研究者还证明过:4×4 的华容道,任何可解局面最多只需 80 步(以单格滑动计)就能还原。这个"最坏情况下的最优步数"被称为这类谜题的"上帝之数"。下次当你纠结某一局要走多少步时,记住——理论上,永远不会超过 80。
The 15-Puzzle has rules you can state in one sentence: slide the scrambled numbers 1 to 15 back into order. Yet it hides a secret that has driven people mad — scramble the board at random, and a full half of all arrangements can never be solved. This is not bad luck; it is an elegant mathematical theorem.
A 19th-century craze
The 15-Puzzle swept Europe and America around 1880, sparking a frenzy not unlike a viral mobile game today. A cash prize was famously offered to anyone who could solve a specific "14–15 swapped" position. Countless people tried obsessively, and none succeeded — because that position is mathematically impossible. The person offering the prize knew it perfectly well.
The key idea: inversions
To see why, we need the notion of an "inversion". Read the numbers on the board (ignoring the blank) left to right, top to bottom, as one sequence. Whenever a larger number appears before a smaller one, that counts as one inversion.
For example, in the sequence 2, 1, 3, the 2 sits before the 1 — that is one inversion. Count every such pair to get the total.
The magic invariant
What happens on each slide? A horizontal move doesn't change the reading order at all, so inversions stay the same. A vertical move jumps a number past three others. After careful bookkeeping, combining that with the row the blank sits in, one quantity provably never changes: the parity of (inversions + the blank's row) is invariant.
Hence, half are impossible
The finished goal state has one fixed parity. Any scramble that can be solved must share that parity. But when you shuffle 15 numbers completely at random, you land on the "correct" and "wrong" parity with 50/50 probability. The wrong half can never reach the goal, no matter how you slide. The infamous "14–15 swap" is exactly one parity flip away — and that is enough.
Why our puzzle is always solvable
For this reason, a responsible 15-Puzzle must never scramble by "fully random arrangement" — that would trap half of all players. The correct method: start from the solved state and make many random legal slides. Because every legal slide preserves the parity invariant, the result is guaranteed solvable. That is exactly how the Day & Night Studio version works — every board you meet can be solved.
An aside: God's number
Researchers have also proven that for the 4×4 puzzle, any solvable position needs at most 80 single-tile moves to solve. This worst-case optimal is the puzzle's "God's number". Next time you agonise over how many moves a board will take, remember — in theory, never more than 80.
想亲手试试?Want to try it yourself?
放心挑战——我们的每一局都保证有解。Play with confidence — every board we give you is solvable.