## HELP! How can I make a sudoku with unique solution?

Advanced methods and approaches for solving Sudoku puzzles

### HELP! How can I make a sudoku with unique solution?

Hi!

I am programming a sudoku game that making a full sudoku board, and then shows to the player only a part of the board and gives the player to solve it.
I already succeed to write a programm that makes a full board, but I have a problem with showing the player a part of the board that I made. I mean, when you solve a sudoku, usually there are 28-30 numbers that are visible and all the rest you must fill by yourself. As I understand there are some rules to which numbers I must make visible to make by board have only one solution. I don't want the player to guess.

What are the rules?

Thanks alot!
Pasha.
pasha

Posts: 1
Joined: 02 March 2006

I guess the biggest requirement is that there be one and only one solution. A good program for generating sudoku's can be found at:
http://magictour.free.fr/sudoku.htm

The code is open source. It's also about as ugly as it can get, but works well and could be integrated into your program. The sticky at the top of this forum has several good sources for existing generator/solver programs.
Mike Barker

Posts: 458
Joined: 22 January 2006

many people who have programmed generator, myself included, first produced solvers. Then rather than starting with a completed grid, you start with an empty grid a fill it, until your solver has found a solution. Which, if you programmed the solver to use techniques based on logic, will be a unique solution.

I have also produced a program which removes clues from puzzles to see if they are still valid puzzles. I ran this on a completed grid once and the puzzle it produced was not very pretty. However the remover program also insisted on removing clues symetrically and when I treid it I used the total symmetry of the square.
ab

Posts: 451
Joined: 06 September 2005

ab wrote:Then rather than starting with a completed grid, you start with an empty grid a fill it, until your solver has found a solution. Which, if you programmed the solver to use techniques based on logic, will be a unique solution.

This might be clear without saying, but I'll add it to this thread anyway to avoid mistakes: In this case you cannot regard any uniqueness-based technique as a techique based on logic. Why? Because it's a logical technique only in a puzzle with one unique solution. Here's a puzzle where your uniqueness test would fail if you allowed your solver to use uniqueness technique as a part of the test:

Code: Select all
`*-----------* |2..|.7.|9.3| |.7.|..9|..8| |..9|2..|.1.| |---+---+---| |...|.12|..7| |...|8.7|...| |4..|95.|...| |---+---+---| |.6.|..3|4..| |7..|1..|.9.| |3.8|.9.|..1| *-----------*`

With singles we get this far:
Code: Select all
` *-----------------------------------------------------------* | 2     8     46    | 45    7     1     | 9     56    3     | | 1     7     346   | 345   346   9     | 56    2     8     | | 56    35    9     | 2     36    8     | 7     1     4     | |-------------------+-------------------+-------------------| | 8     9     35    | 34    1     2     | 56    456   7     | | 56    235   2356  | 8     34    7     | 1     45    9     | | 4     1     7     | 9     5     6     | 8     3     2     | |-------------------+-------------------+-------------------| | 9     6     1     | 7     2     3     | 4     8     5     | | 7    *245   25    | 1     8    *45    | 3     9     6     | | 3    *45    8     | 6     9    *45    | 2     7     1     | *-----------------------------------------------------------*`

To avoid the Bug-lite pattern we could solve r8c2=2 and then solve the remaining cells as singles. But in fact this puzzle has 5 solutions.

Can you see where the test fails?

RW
RW
2010 Supporter

Posts: 1000
Joined: 16 March 2006