keropnav.blogg.se

Sudoku puzzle generator algorithm
Sudoku puzzle generator algorithm









sudoku puzzle generator algorithm

'hard-code the initial state, which can be any valid sudoku puzzle

SUDOKU PUZZLE GENERATOR ALGORITHM CODE

I am afraid that I have the time to neither convert the code to .NET (although it is very easy) nor optimize it. So I will copy-paste it here, and hope not to be flamed for incompetent programming: This is the termination criterion, as the current state is a valid Sudoku puzzle. It turns out that this counterpart ("1") is the same as the cell we originally swapped. We locate the other instance of "7" in the first row, which is located in the seventh column, and swap it with its counterpart in the second row: We fixed the "4"'s, but now there are two "7"'s in the first row. We locate the other instance of "4" in the first row, and swap it with its counterpart in the second row: For instance, there are two fours ("4") in the first row. Suppose we want to swap the top-left cell ("1") with the one below it ("4"): initial puzzle). For instance, we may want to use this one: It turns out that any cell can be swapped with another one (in the same 3 x 3 matrix, of course), as long as the corresponding modifications are made along their rows or columns.Īny valid configuration can be used as seed (i.e.

sudoku puzzle generator algorithm

Instead of using a brute-force method, it is possible to modify an existing Sudoku puzzle so that it remains valid. In any case, I am sharing: Algorithm description The algorithm for the creation of new puzzles is interesting, although probably not the most efficient, and surely someone else has thought it before me. Of course, very soon I found myself on my laptop, writing a program for creating and solving Sudoku puzzles.

sudoku puzzle generator algorithm

During a hot summer I used to spend my time solving Sudoku puzzles at the beach - which is quite fun if you are in a must-not-work mode. Today I stumbled on an program I had written years ago.











Sudoku puzzle generator algorithm