Help with Brute-Force Sudoku Solver?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Help with Brute-Force Sudoku Solver?

  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Help with Brute-Force Sudoku Solver?

    This solver seems to work for some Sudokus, but it does nothing for others. Can anyone see something wrong? Thanks.

    Oh, and my Sudoku is made of a two-dimensional array.

    public void solve()
    {
    boolean findEmpty = false;
    int i = 0;
    int j = 0;

    for ( i = 0 ; i < 6 && !findEmpty ; i++ )
    {
    for ( j = 0 ; j < 9 && !findEmpty ; j++ )
    {
    if ( sudoku.getGrid()[i][j] == 0 )
    {
    findEmpty = true;
    }
    }
    }

    i--;
    j--; // return i and j to values of row and col where sudoku is empty

    for ( int k = 1 ; k <= 9 ; k++ )
    {

    if ( isLegal( i , j , k ) )
    {
    sudoku.getGrid()[i][j] = k;

    solve();
    if ( isComplete() )
    return;

    }
    }

    sudoku.getGrid()[i][j] = 0;

    }
    Last edited by Sinfonia; March 7th, 2009 at 08:50 PM.

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: Help with Brute-Force Sudoku Solver?

    Please use the code tags, it is hard to read code without them.

    Personally I don't know how your solver is working for "any" Sudoku. You are checking a 6 by 9 area and a Sudoku puzzle is 9 by 9... I would run it in debug mode and step through the code if I were you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center