我最近想看到,我是否能够在营地内(首先)解决一个容易的骗局。 我知道,由于方案拟定的原因,营地实际上不是巧妙的,但我知道,营地是最好的,我在java和c的设计方面存在问题。 尽管如此,我看不出为什么不工作的原因。
首先,我不想问你,因为那里有一些已经解决的read子。 但我发现,这些解决办法对我来说过于复杂,难以理解(其他语言、复杂的障碍),也不符合我的目标。
我的问题是:一些人能否在我的目标的基础上向我提出 h? 我只想一个简单的“oku”解决器,而不作gues,而只是背后。
算法认为:
$cell; // 1-81 - as parameter of the recursive function solve()
$value; // 1-9 - as parameter ...
class Sudoku {
function solve($cell = 1, $value = 1) {
// skipping values
if the current cell is fix:
return solve(cell++, $value);
// testing values (logic)
if not:
if the value is within the square (3x3) itself:
return solve($cell, $value++);
if the value is within the row:
return solve($cell, $value++);
if the value is within the col:
return solve($cell, value++);
if the value is bigger than 9:
return solve($cell--, $value_prev);
// all test passed, add the new value to list
$this->values[$cell] = $value;
if all fields are filled:
return;
if there are fields left:
return solve($cell++, 1);
}
}
如果我设立空白处,它将在43个牢房之前正确填满。 脚印有致命错误: 致命错误: 允许的活度为134217728英寸(用于分配261904英特)。
这些数值如下:
1 2 3 | 4 5 6 | 7 8 9
4 5 6 | 7 8 9 | 1 2 3
7 8 9 | 1 2 3 | 4 5 6
2 1 4 | 3 6 5 | 8 9 7
3 6 5 | 2 1 4 | . . .
I guess there is an infinite loop or something that causes this crash. Maybe it is not solvable like this. I just wanted to know if I am doing right or what I forgot to check. I also tried this algorithm with fixed values from an easy-sudoku. It crashes too ... maybe there is to much backtracking.
Finally, I want to say that I m not against better solutions but I just want this to work. If you cannot give me an answer based on this you can have a look at the php file:
Edit: sudoku2.php
提前感谢。