Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
Why is the i variable in my for loop not changing

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
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda