Saturday, September 15, 2007

Sudoku Solution Generator

The sudoku solution generator-

I developed this sudoku solution generator on C++ platform using the Turbo Cpp compiler. It uses backtracking as the prime algorithm to arrive at the solution.

In the following program what I have done is first found all the permutations of numbers 1 to 9 and stored this in a file which sized almost 4MB. The puzzle is then entered.

A solution to every row is found gradually after matching it from the permutations generated into sequential permutation file and keeping in mind the constraints of the sudoku puzzle. The first appearance of a possible solution (in the order of appearance in case of ‘bottom up permutation algorithm’) is considered as the intermediate solution to that row and then the program proceeds to find the solution to the next row. Solutions to all the rows are hence found and if any row does not have a solution possible and the end of the permutation file is reached then the solution of the previous row is re-examined and if the same has no solution as well then the row above is re-examined.

On the newer GCC compilers it gives a 3 sec average case.

for the complete code u can reach me at ishesh@gmail.com