Thursday, November 26, 2015

Sudoko Solver



You might have solved sudoko if not try solving it LINK.

Only 3 main constrains
A number among 1-9 appears
1. Only Once is a row
2. Only Once in a column
3. Only Once in a 3 x 3 matrix

Programatically it can be solved in following manner. Each successive step is improvement above it


        Generate all possible Sudoko games and match it with input
                 Possibilities - 9 values per square, Total = 10^38 possibilities
                 Time : it takes billion of years to solve it. 13.5 Billion Year Solar system started forming.
        Use Back tracking 
                 Greatly reduces the number patterns generated to match input.
                 Choose 1st available empty cell, Choose 1st available safe value 
                 Continue filling for rest of empty cells.
        Constrain on empty Cells
                 Greatly reduces the number of paths taken during back tracking.
                 Search for empty cell which has least possible values, ie. the probability of failure reduces
        Constrain on values possible per empty Cell
                 Further reduce the probability of failure.
                 Pick up value in the cell which least probability to fail by 1 step further.




Reference Links
  1. Peter Norvig 

No comments:

Post a Comment