A proper Sudoku has exactly one solution. Today you turn the solver into a solution counter that stops at two, giving you a uniqueness test - the tool the generator depends on.
Count a puzzle's solutions up to a limit, and report whether it is uniquely solvable.
A well-formed Sudoku is defined by having exactly one solution. To check that, you do not need to enumerate every solution - you only need to know whether there is one, none, or more than one. So the counter reuses the full solver’s search but, instead of returning the first solution, it keeps going and tallies each complete grid it reaches, and it stops the moment it hits two. Counting past two would be wasted work; two already proves non-uniqueness.
That capped count is exactly the uniqueness test: a count of 1 means a proper puzzle, 0 means impossible, and 2 means ambiguous. The crafted example here has just four blanks arranged so two digits can swap, giving precisely two solutions - the smallest kind of ambiguity. This test is the backbone of the next lessons: the generator will remove clues only as long as the puzzle stays at a count of 1.
// like Solve, but keep searching and tally leaves; stop once you reach limitfunc CountSolutions(g [81]int, limit int) int {count := 0// search(cg): propagate; on solved, count++; else branch every candidate,// returning early once count == limitreturn count}func IsUnique(g [81]int) bool { return CountSolutions(g, 2) == 1 }