samedi 22 février 2020

How to select the next empty cell when trying to solve sudoku?

I am trying to code my own sudoku solver as a self-learning project. By specifying a random state seed, I can ensure that a randomized 9x9 board containing 25 0's will be solved without the use of a backtrack. When specifying 26 0's, the algorithm gets stuck during a backtrack. This is because my algorithm is recursive - for each empty 0 cell, the algorithm first finds the most optimal cell (in terms of uniqueness, not in terms of sums). When back-tracking, the algorithm repeatedly revisits the same 2 optimal cells. I am wondering about the best approach forward.

Approach 1:

Add additional methods to determine the optimal cell in terms of sums.

Approach 2:

Randomize the locations of the 0 cells at each iteration.

Any information about this would be helpful. This question contains no code because it is a bit long and not necessary to discuss the question. If there is a more appropriate place to ask this, let me know.




Aucun commentaire:

Enregistrer un commentaire