检查/消除回溯函数javascript中的不同行/列
我有这段代码来解决3x3数独(只需要检查行/列,一个块中可以有4个相同的数字,例如这是一个好的: 123 231 312 ) 我有一个函数fillsquare,输入一个数组[[1,2,0],[0,3,1],[3,0,2]],其中0需要更改为正确的数字检查/消除回溯函数javascript中的不同行/列,javascript,recursion,sudoku,backtracking,Javascript,Recursion,Sudoku,Backtracking,我有这段代码来解决3x3数独(只需要检查行/列,一个块中可以有4个相同的数字,例如这是一个好的: 123 231 312 ) 我有一个函数fillsquare,输入一个数组[[1,2,0],[0,3,1],[3,0,2]],其中0需要更改为正确的数字 function fillsquare(square){ for (var a = 0; a<4; a++){ for (var b = 0; b<4; b++){ if (square[a][b] === 0)
function fillsquare(square){
for (var a = 0; a<4; a++){
for (var b = 0; b<4; b++){
if (square[a][b] === 0){
// do the function to check whether I can enter the right number
}
else {
// ?????????????????????
}
}
}
}
我希望这是一个有点清楚,这是翻译;)
function fillSquare(square) {
find first 0 in square
if (there is no 0) {done!}
else {determine every value that can be put on the place with the zero
(check column and row) save them for example in a temprary row
for (every possible value) {
fillSquare(square with value filled in place)
}
}
}