# My Weblog

## Sudoku solver

Solving sudoku is having fun ,thinking recursively and keep thinking until you get solution. As being a programmer i tried to solve sudoku using computational power but till now my code can solve only easy sudoku so i have try some fancy techniques as given on http://en.wikipedia.org/wiki/Algorithmics_of_sudoku . For solving hard sudoku we must have to use DFS technique but till now i can’t figure out.

```
int main()
{
int mat[10][10];
for(int i=1;i<=9;i++)
for(int j=1;j0)
{
prepro=0;
for(int i=1;i<=9;i++)
for(int j=1;j<=9;j++)
if(mat[i][j]==0)
{
int igp=((i-1)/3)*3;
int jgp=((j-1)/3)*3;
for(int w=1;w<=9;w++)
tmp1[w]=1;
for(int m=1;m<=9;m++)//row
if(mat[i][m])
tmp1[mat[i][m]]=0;
for(int m=1;m<=9;m++)//column
if(mat[m][j])
tmp1[mat[m][j]]=0;
for(int m=1;m<=3;m++)//box
for(int n=1;n<=3;n++)
if(mat[m+igp][n+jgp])
tmp1[mat[m+igp][n+jgp]]=0;
int count=0,sol;
for(int m=1;m<=9;m++)
if(tmp1[m])
count++,sol=m;

if(count==1)//only one possible solution
mat[i][j]=sol,prepro=1;
}
}
//printf("\n");
for(int i=1;i<=9;i++)
for(int j=1;j<=9;j++)
printf("%d%c",mat[i][j],(j<9)?' ':'\n');

}
```