It's probably just a small mistake, but I can't figure it out. I'm making a program to check if a sudoku has multiple solutions but the variable i in my for loop doesn't transfer to the solve function.
When I call the solve function with a hardcoded number then it works as expected. But if not then it uses the value i is initialized to and doesn't change.
function unique(bo) {
let boards = []
let i = 0
for (i = 0; i <= bo.length; i++) {
let num = i
console.log(num) //returns i correctly
let board = []
board = solve(bo, num) //num is not updated
if (board) {
boards.push(board)
}
}
if (new Set(boards).size === 1) {
return true
} else {
return false
}
}
function solve(bo, st) {
let numberList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
numberList = Rotate(numberList, parseInt(st))
let found = findEmpty(bo)
if (!validateBoard(bo)) {
return false
}
let row, col;
//any more left?
if (!found) {
return bo
}
[row, col] = found
//return bo
for (let i = 0; i < numberList.length; i++) {
if (validate(bo, numberList[i], [row, col])) {
bo[row][col] = numberList[i];
solve(bo, st)
}
}
if (findEmpty(bo)) {
bo[row][col] = 0;
}
return bo
}