Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!