Jump to content

new to java in need of dire help with sudoku solver

- - - - -

  • Please log in to reply
1 reply to this topic

#1
peteryang22

peteryang22

    Newbie

  • Members
  • Pip
  • 1 posts
private boolean solve(int pos){

        if (pos == positions){

            //we have guessed all positions in the puzzle

            return Util.checkSolution(this.puzzle);

        }

        int row = pos/squares;

        int col = pos%squares;

        boolean solved = false;



        if(!puzzle.fixed(row, col)){

            int i = 1;

            while(!solved & i <=squares){

                // for(int i = 1; i <= squares; i++){

                    try

                    {

                        puzzle.setCellValue(row, col, i);

                    } catch (FixedCellException e)

                    {

                        // TODO Auto-generated catch block

                        return solve(pos+1);

                    }

                    solved = solve(pos+1);

                    i++;

                }

            

            return solved;

        }

     

          return solve(pos+1);

        


    }

sorry new to the forum, pardon me if im posting in the wrong place.
im creating a brute forced sudoku solver with recursion
because debugger in my eclipse isnt working, i cant really debug this, and im not really good at tracing by hand. but no matter how i trace it i can find the problem with it. a main method calls this with return solve(0);

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Can you explain to me in pseudo code the logic you're attempting to use to solve the puzzle? Then I can tell you if your code is achieving that logic or not.

By logic I don't mean generically brute force or some other solution strategy. I mean a step-by-step explanation of the implementation of your brute force strategy.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users