是否有更有效的编码,最好没有每个有效数独设置的数据库?
是。我可以想到一种编码,根据条件的不同,可以改进您的149位编码,以6或9位最小拼图。这没有数据库或任何其他解决方案或部分板的注册。它去了:9×9
首先,您使用位对数字m进行编码,使面板中的出现次数最少。接下来的4位编码的实际数量ℓ次中号出现。接下来的7个ℓ比特编码每个中的位置的米出现。4m4ℓm7ℓm
以下位是标志,指示其余位置是否有数字(您只需跳过m所在的位置)。每当这些位之一为时,接下来的3位将指示其为哪个数字(在无m的有序集合{ 1 ,… ,9 }中)。例如,如果米= 4和3位,然后在所述板上的相应位置的数量是在该组中的第5次(从0计数){ 1 ,2 ,3 ,81−ℓm1
{1,…,9}mm=4101
,因此它是 6。数字 j < m将被二进制编码为 j - 1,而数字 j > m将被编码为 j - 2。由于我们已经写入了 ℓ个位置,因此在此步骤中,将仅添加 3 (n - ℓ )位来编码电路板的其余部分。{1,2,3,5,6,7,8,9}6j<mj−1j>mj−2ℓ3(n−ℓ)
B=4+4+7ℓ+(81−ℓ)+3(n−ℓ)=89+3ℓ+3n.
n=17ℓℓ≤⌊n/9⌋B
n∈{17,18,19}n=20ℓ=0N=92⌊log2N⌋N=16
Example. Consider the following board with n=17 clues.
. . . . . . . 1 .
4 . . . . . . . .
. 2 . . . . . . .
. . . . 5 . 4 . 7
. . 8 . . . 3 . .
. . 1 . 9 . . . .
3 . . 4 . . 2 . .
. 5 . 1 . . . . .
. . . 8 . 6 . . .
Here, no number does not appear on the board, and numbers 6, 7 and 9 appear only once. We take m=7 (0111
) and ℓ=1 (0001
). Reading the positions from left to right and then from top to bottom, m appears in the position 36 (0100100
). Thus, our encoding begins with 011100010100100
.
Next, we need seven 0
s, one 1
and the 3-bit encoding of the number 1, then a 0
followed by a 1
and the 3-bit encoding of 4, etc. (0000000100101100
). Eventually, we will skip the position where m=7 is, and we will encode 8 as 110
(the 6th number counting from 0 on the list 1,2,3,4,5,6,8,9) and 9 as 111
. The full encoding goes as follows:
// m=7, l=1 and its position on the board.
011100010100100
// Numbers 1 and 4 at the beginning. Note that 1 is encoded 000, and 4 is 011.
0000000100001011
// Numbers 2 and 5.
0000000001001000000000001100
// Numbers 4 and 8. We skip the appearance of 7 and encode 8 as 110.
010110001110
// 3, 1 and 9. 9 is encoded as 111.
00010100000100001111
// 3, 4, 2, 5, 1, 8, 6 and the last empty cells.
0000101000101100100100011000100000000000111001101000
The complete encoding is 01110001010010000000001001010110000000001001000000000001100010110001110000101000001000011110000101000101100100100011000100000000000111001101000
, and the reader can check the length of that string is indeed 143 :-)