Free Tarot Readings

Sudoku Algorithm Part 2 Removing numbers from the board

To create a Sudoku puzzle we remove numbers from the Sudoku board so there can be only one possible solution. We can’t just remove any number. Each time we remove a number we must verify that the board can be solved. We will need to try and solve the Sudoku puzzle each time we remove a number using the known methods (ns,hs,np,ir,xw,yw). If we only use the simplest methods to see if the puzzle can be solved, then our puzzle will be simpler. For example using only ns and hs methods we will have a very simple Sudoku puzzle. If we use all the methods (ns,hs,np,ir,xw,yw) our puzzle has the potential to be more difficult.

My Sudoku number removing algorithm uses a while loop. For each loop we randomly remove a number, then try to solve the puzzle. If we can solve the puzzle we try to remove another number. If we cannot solve it, we restore the number and try to remove a different number. During the solve phase, we keep track of what methods were used to solve it (ns,hs,np,ir,xw,yw) to gauge it’s difficulty.

During the solve phase we must recalculate all the possible numbers for the empty cells (Potential array) each time a cell is filled in.

My breakout condition for the ‘while loop’ is set by a time limit. My code is sufficiently fast that 5 seconds is plenty to get the Sudoku board down to 25 visible numbers.