CHAPTER 13

image

Implementing “Backtrack”

As I have already explained in Chapter 2, backtracking is a nice way of saying “guessing.” When you exhaust all strategies you know, you can only pick a cell that you haven’t yet solved and try out one of its candidates. If you reach a contradiction, you need to revert the Sudoku grid back to what it was before your arbitrary choice and try another candidate—hence the “back” of backtracking.

The Solver program with the analytical strategies illustrated in the previous chapters solved 99.85% of the 30,000 generated puzzles (see Chapters 1416 for more details), but for the remaining 0.15%, backtracking was the ...

Get Sudoku Programming with C now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.