Sudoku Generator/Solver

17.09.2008 - Coding

Out of sheer boredom, I wrote a Sudoku generator one evening at WK. That was fun, but it didn't fill the evening. So I also wrote a Sudoku Solver, which was allowed to solve the generated Sudukus again. A perpetum mobile so to say ;-)

Sudoku Generator

My Sudoku generator is based on a simple property of Sudokus.: Two columns or two rows can be swapped without violating the rules of Sudoku, as long as they are swapped within one third, i.e. columns/rows 1-3, 4-6 and 7-9 can be swapped arbitrarily. If you start now with a "banal" Sudoku, which contains the numbers 1-9 in each row shifted by 4 to the right (compared to the upper row), and swap sufficiently long, randomly two columns and rows each, you get a "random", but already filled Sudoku. Now you only need to delete any number of fields - the more the more difficult the Sudoku is to solve.

to create four new Sudokus.

Sudoku Solver

The Sudoku Solver solves the given (or empty) Sudoku recursively according to the brute force method: For each empty field, simply insert the numbers 1-9 and test whether one of the Sudoku rules has been violated. If no, we move on to the next empty field. If yes, the next number is tried. If no numbers from 1-9 fit in the empty field, backtracking to the previous empty field occurs and there the next possible number is tried until the whole Sudoku is solved.

Enter numbers in the empty fields and then click "Solve Sudoku".