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

164
Vistas
Backtrcing algorithm not worked properly

I've written in Python Sudoku solver and backtarcing problems... And in the second Layer soduko is disabled.

function find(){
            for (let x=0;x<mat.length;x++){
                let y
                y = mat[x].findIndex((e)=>e===0)
                if (y!=-1){
                    return  [x,y]
                }
            }
        }
        function is_valid(x,y,num){
            
            if (mat[x].filter(target => target===num).length >=2){
                return 0
            }
            for(let i=0;i<mat.length;i++){
                if (i === x){
                    continue
                }
                if (mat[i][y] === num ){
                    return 0
                }
            }
            let X = x - x % 3
            let Y = y - y % 3 
            let N = 0
            for (let i =0;i<3;i++){
                for (let j =0;j<3;j++){
                    if(mat[i+X][j+Y]== num){
                        N+=1
                    }
                    if (N==2){
                        return 0
                    }
                }
            }
            return 1
        }
        
        function solve(){
            try {
                [x,y] = find()
            }catch{ 
                alert('solve')
                return 1
            }
            
            for (let i = 1 ;i<10;i++){
                mat[x][y] = i;
                console.log(mat[x])
                if (is_valid(x,y,i)){
                    solve()
                }
            }
            mat[x][y]=0
            }
            solve()

What's my code problem? I want first put the value in the soduko and then check if the value is valid or not.. and solve it

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