Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python solution to sudoku solver fails to solve the whole sudoku. #206

Open
EnriqueOrtiz27 opened this issue Dec 30, 2020 · 0 comments
Open

Comments

@EnriqueOrtiz27
Copy link

EnriqueOrtiz27 commented Dec 30, 2020

This is a specific problem. With solution 15.10, Implement a Sudoku Solver, it should be noted that the algorithm is not able to solve a sudoku. When I comment the fourth to last line:

# partial_assignment[i][j] = empty_value

I can see how this functions fills a sudoku. I used the example provided by you on page 63, and available on the internet, which is a 2D array:

sudoku  = [
          [5,3,0,0,7,0,0,0,8], #row 1
          [6,0,0,1,9,5,0,0,0],
          [0,9,8,0,0,0,0,6,0],
          [8,0,0,0,6,0,0,0,3],
          [4,0,0,8,0,3,0,0,1],
          [7,0,0,0,2,0,0,0,6],
          [0,6,0,0,0,0,2,8,0],
          [0,0,0,4,1,9,0,0,5],
          [0,0,0,0,8,0,0,7,9] #row 9
           ]

This configuration, as well as its solution, can be found in wikipedia

Running your function with the added comment I mentioned, I get this:

[[5, 3, 0, 0, 7, 0, 0, 0, 8],
 [6, 7, 0, 1, 9, 5, 0, 0, 0],
 [1, 9, 8, 0, 0, 0, 0, 6, 0],
 [8, 1, 0, 0, 6, 0, 0, 0, 3],
 [4, 5, 0, 8, 0, 3, 0, 0, 1],
 [7, 0, 0, 0, 2, 0, 0, 0, 6],   <<<----- the function stopped in the sixth row, second column. 
 [9, 6, 0, 0, 0, 0, 2, 8, 0],
 [2, 0, 0, 4, 1, 9, 0, 0, 5],
 [3, 0, 0, 0, 8, 0, 0, 7, 9]]

The function stopped at the sixth row, second column because the values filled in that same column are incorrect (and by incorrect I mean we can't solve the whole sudoku with those values)

As we can see in the solution to the whole sudoku (also on page 63), in the second column we need [3,7,9, 5, 2, 1, 6, 8, 4]. However, instead of that initial 5 after the 9, the algorithm will put in a 1 (because it's a valid entry) but that makes it impossible to solve the whole sudoku.

Note: This algorithm is also unable to complete an empty sudoku grid (9 by 9)

I understand the complexity of the problem and how grueling it would be to account for these changes. I would just like to hear your thoughts on this :)

Thanks, the book is really awesome btw :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant