algorithmpuzzlesudoku

How to generate Sudoku boards with unique solutions


How do you generate a Sudoku board with a unique solution? What I thought was to initialize a random board and then remove some numbers. But my question is how do I maintain the uniqueness of a solution?


Solution

  • Easy:

    1. Find all solutions with an efficient backtracking algorithm.
    2. If there is just one solution, you are done. Otherwise if you have more than one solution, find a position at which most of the solutions differ. Add the number at this position.
    3. Go to 1.

    I doubt you can find a solution that would be much faster than this.