For your reference, this is part of the algorithm I use to generate my own sudokus:
Code: Select all
generate_sudoku(grid)
if grid has no solution // 1
return false
if grid has exactly one solution // 2
return true
select a random empty square s in grid
for i = 1 to 9 // 3
assign square s in grid with value i
if generate_square(grid)
return true
return false
Call generate_sudoku() with an empty grid.
A few points:
1. As to how to find out how many solutions a grid has (marked with 1 and 2), its simple recursion and a person doing a BSc in Information Systems should know how to do it.
2. For better randomness of values, the loop marked with 3 can be modified, I also leave it to you to figure this out.
3. The grid generated by generate_sudoku() is 99% of the time not minimal. I leave it to you to figure out how to make it minimal. On average, after making it minimal, my generator creates a grid with 20+ clues.
4. There are no gurantees as to how easy or difficult the generated sudoku is. It can be terribly easy, it can be terribly hard.
Just for fun, this is one of the hardest sudokus that is generated by my generator. To solve it, you need very advanced techniques. SudoCue uses a couple of almost locked sets and one 3D Medusa colouring to solve it. I have yet to figure out how to interpret the colours shown by SudoCue for the 3D Medusa technique though.
Code: Select all
006200000000004300800035000020000000000000731190000060004053002000700600050082100