Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda