Sunday, May 17, 2020

Simple Sudoku Maker

There is much on the Internet about how to solve Sudoku puzzles. However, there is little about how to make a Soduku puzzle. The following shows a simple non-trial-and-error method to make a Sudoku puzzle that satisfies the requirements. That is, each of the rows, columns, and nine 3x3 blocks of cells contain each number 1-9 exactly once. Also, many alternatives can be made from this result. 

Make the Base Puzzle

First enter the numbers shown below in red and blue backgrounds. Note that the numbers in blue are copied from the 2nd and 3rd rows of numbers in red. Then going down each column, add 1 to get the number in the next row until the puzzle is filled, with one exception -- 1 follows 9. 

There may be, but I doubt there is a simpler method. I have seen only one other method that is about as simple (link). 

Many alternatives can be made from this Base Puzzle. For each of numbers 1-9, generate a random number, then rank the random numbers. The random numbers and ranks are easily produced in a spreadsheet. Then pair each number 1-9 with its random number's rank among all the random numbers, and create the next puzzle from the ranks as shown below. In effect, the numbers in the Base Puzzle are shuffled while still meeting the requirements. For example, a 1 in the Base Puzzle yields a 6 in the Output Puzzle, a 2 in the Base Puzzle yields a 4 in the Output Puzzle, and so forth. 

Base Puzzle
1 4 7 2 5 8 3 6 9
2 5 8 3 6 9 4 7 1
3 6 9 4 7 1 5 8 2
4 7 1 5 8 2 6 9 3
5 8 2 6 9 3 7 1 4
6 9 3 7 1 4 8 2 5
7 1 4 8 2 5 9 3 6
8 2 5 9 3 6 1 4 7
9 3 6 1 4 7 2 5 8

Number        random          rank
1 0.47460201 6
2 0.66240441 4
3 0.30831936 7
4 0.71401711 2
5 0.28997433 8
6 0.68553150 3
7 0.05804816 9
8 0.73011822 1
9 0.47537093 5

Output Puzzle
6 2 9 4 8 1 7 3 5
4 8 1 7 3 5 2 9 6
7 3 5 2 9 6 8 1 4
2 9 6 8 1 4 3 5 7
8 1 4 3 5 7 9 6 2
3 5 7 9 6 2 1 4 8
9 6 2 1 4 8 5 7 3
1 4 8 5 7 3 6 2 9
5 7 3 6 2 9 4 8 1
Equally simple is to create the Base Puzzle by transposing the numbers in red and blue and then adding 1 in rows rather than in columns. The result would be the above Base Puzzle fully transposed. It would match the one at the URL linked above, but its author fills the puzzle by shifting rather than adding. The link also uses a different shuffling method to make alternatives.

Finishing is easy. Delete as many numbers from the Output Puzzle as desired. I leave allowing only one solution to others.

No comments:

Post a Comment