Sudoku Maker

Create your own puzzle. Click button --->

Read about this Sudoku puzzle program below


Saturday, January 01, 2011

Glitch in Sudoku Program is Fixed!

After four years of my Sudoku program working without problems, Google made some changes to Blogger that messed up my Sudoku program. Thanks to the commenter who alerted me to this problem. The problem is now fixed. The program now executes as before. Just select the "create puzzle" button on the right to create your own Sudoku puzzle.

Tuesday, December 11, 2007

Updates to My Sudoku Puzzle Maker

I'm afraid with little free time it has been a while since my last update to my Sudoku puzzle generator. I fixed a few problems with the generator. It had stopped working due to a change in what blogger adds into the template. It was messing up my javascript code. I tweaked the code so this doesn't happen. I also added a close statement so the new page that pops up won't look like it's in a running mode. This makes the Sudoku puzzle printable without having to click the browser stop button.

I've realized that creating a valid Sudoku puzzle isn't easy. My version 2.0 attempted to ensure a unique solution. As this Wikipedia article describes "a proper puzzle has a single (unique) solution." Version 2.0 improved the odds that the puzzle would be unique, but it's not 100%. The chance of a non-unique solution increases on the higher levels when there are fewer givens. So if you're looking for an easy Sudoku or a kid Sudoku (under level 5), you probably won't have to worry about multiple solutions. If you think there may be multiple solutions, use this Sudoku Solver to find out. It'll detect and display multiple solutions. I'll keep working on Version 3.0 which will hopefully be able to guarantee a unique solution in all cases.

Update: As of February 2010, I still haven't developed version 3.0 of my Sudoku Maker program. As I mentioned, the uniqueness issue is a tough one.

Sunday, February 12, 2006

Preventing Multiple Puzzle Solutions

I've released version 2.0 of my Sudoku Maker program. When I first coded the program, I assumed the hard part was finding all the numbers to make up a Sudoku table. The problem of which squares to blank out seemed easy. After some reading and studying, I realize this is backwards. The hard part is determining which squares to blank out or mask.

The first thing I realized that the hardness level is not determined by only the number of masked squares. Two puzzles can have the same number of masked squares and be drastically different in difficulty. My program determines which numbers to mask in a random method and the easier levels mask fewer numbers. In future versions I'll try to develop better algorithms.

Random masking has a more serious problem in Sudoku puzzles. That problem is the possibility that a puzzle could have multiple solutions. In this second version of my program, I've added two functions that greatly reduce the chance of multiple solutions.

After version 1.0 I noticed two cases that can cause multiple solutions. First is when there are four numbers in two separate 3x3 boxes that are masked. This is shown in example one below. The multiple solutions have the 8 and the 1 in bold. In this example the 8 and the 1 for both columns can be flipped. This flipping maintains the 3x3 box and column requirements of no repeat numbers. By flipping the 8 and 1 in both columns, the row requirement is maintained.

These 2x2 combinations can also appear from top and bottom in addition to left and right. Also, these are quite common. To ensure a unique solution, my version 2.0 program looks for these 2x2 combinations after I generate the 9x9 numbers. I then randomly pick one of the four numbers that cannot be masked. If at least one of the four numbers is not masked, only one solution is possible.

After some more thought I realized that other combinations may cause similar multiple Sudoku solutions. After a lot of experimentation, I came up with a 3x3 combination that can cause multiple solutions that is similar to the 2x2 box. This is shown in example two below. In this case, a column of 3 numbers exist in 3 different 3x3 regions. If all 9 numbers are masked, there exists 6 possible solutions to the Sudoku puzzle. As before this can be prevented my ensuring at least one of the nine numbers are masked. As you would suspect, this 3x3 combination is much less likely than the 2x2 combination.

As more and more squares are masked, the chance of multiple solutions is likely to rise. I'm sure there are likely other combinations that I have not considered that could create multiple solutions. If you know of other combinations that can create multiple solutions, please leave a comment.

Example One - 2x2 Combination

The puzzle to the right has
has 2 solutions due to the
4 specific blank squares.
The two tables below show
the 2 solutions. The top and
bottom 8 and 1 can be
interchanged and still meet
the row, column and
3x3 box requirements
of Sudoku.
  
3 7 8  6 5 9  2 1 4
1 5 4  3 2 8  7 6 9
6 2 9  4 7 1  5 3 8

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

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

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

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

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

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

Example Two - 3x3 Combination

The puzzle to the right has
6 solutions. The numbers
2, 5 and 7 are required
in all three blank columns.
Each column must have a
different order of these
numbers to maintain the
row requirement. Each
column may contain any of
the 3 combinations just so
each column has a
different order.
  
3   8  6   9    1 4
1   4  3   8    6 9
6   9  4   1    3 8

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Friday, January 06, 2006

Make Your Own Sudoku Puzzles

Overview

I enjoy puzzles with very simple rules that can be exceedingly difficult. Sudoku fits that definition. The rules are very simple: find the missing numbers so there are no repeat numbers in any rows, columns or 3x3 regions.

There are many Sudoku websites. I decided to make my own Sudoku website and Sudoku program because I thought it would be a cool JavaScript program. Also, I thought I could design some features that I haven't found in other places.

The most important feature is a wide range of levels that include very easy levels suitable for young children. Levels 1, 2 and 3 are very easy. The idea is to introduce Sudoku without making it look too difficult. After the person gets the hang of it, higher levels can be tried.

Level 1 only masks one or two numbers per row. This can make the puzzle easy enough for a young child. The rows with 2 numbers masked require the child to look at the column or 3x3 box to decide on the missing number instead of just the row. I did these simple Sudoku puzzles so that preschool children won't be overwhelmed. These very simple puzzles can help ease a young child into the fun of Sudoku puzzles at a very young age.

I decided not to make the program interactive. I think most people would prefer doing the puzzle on paper, so I designed the program to display the puzzles and answers in a window that can be easily printed.

Instructions:

  1. Review and Print Example: To learn about the simple rules of Sudoku, click the example button. A new window will open with a brief description of the rules and an example table will be displayed. This can be printed if needed. Be sure to close window before continuing.
  2. Set Default Level: The default level is 5. Enter a level in the text box to change the level. Levels range from 1 to 12. Level 1 should be suitable for preschool children. Level 12 is the hardest level.
  3. Create and Print Puzzle: To make your own original Sudoku puzzle, click the create button on the right. Puzzles are generated in a completely random method. Two tables will shown in the window. The first is the puzzle. The second one with the answers appears below. This is intended to be printed with the answers appearing on the second page.
  4. Create More Puzzles: Close the puzzle window before clicking the create button again. This can be repeated as many times as desired. Every puzzle is tagged with a random number so that the puzzle and answer tables can be matched.

Problems?

  • Alert Box - If you see an alert box warning that asks you if you want to abort. Click NO. This is due to the program's high computation effort. The program only needs a few more seconds to complete. It has been designed with time-outs to make it impossible to lock up your PC. After you click NO on the alert box, be sure to bring the generated window to the front so you know when it has finished.
  • Nothing Happens When You Click the Button - Have you closed the previous window? After you create a puzzle or display the example, you have to close that window before creating a new puzzle.
  • Puzzle Window Doesn't Finish - On some browsers it may appear that the puzzle window hasn't finished even after the tables have been displayed. It may appear that more is being downloaded. Just click the browser stop button. This may be required before printing.
  • Printer Problems - Print the puzzle or example window just like you would any other webpage using your browser print option. You may need to click the browser stop button before printing.
Sudoku Websites