/*zero's out any possibles resulting from a cell being assigned a value, in all boxes*/ void BoxPossibles() { // int box, c, col, lowcol, lowrow, n, r, row; lowrow = 1; lowcol = 1; for(box = 1; box < 10; box++) { for(row=lowrow; row 9) { lowcol = 1; lowrow += 3; } } } /*zero's out all possibles for a cell with a value, in a column*/ void ColPossibles() { int c, i, r, n; for(c = 1; c < 10; c++) { for(r = 1; r < 10; r++) { if(A[r][c]) { n = A[r][c]; for(i = 1; i < 10; i++) PossAll[i][c][n] = 0; } } } } /*zero's out possibles across the row, for any sqr assigned a value*/ void RowPossibles() { int i, n, r, c; for(r = 1; r < 10; r++) { for(c = 1; c < 10; c++) { if(A[r][c]) { n = A[r][c]; for(i = 1; i < 10; i++) PossAll[r][i][n] = 0; } } } }
int check(int a,int b); int check1(int a,int b,int c,int d); void recursive(int x,int pos[82]); void scaledown(int pos[82]);
int pos[82]; int q=1; long c=0; int ch[10]={0,1,2,3,4,5,6,7,8,9}; int ar[10][10]= {{0,0,0,0,0,0,0,0,0,0}, {0,8,6,0,0,2,0,0,0,0}, {0,0,0,0,7,0,0,0,5,9}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,6,0,8,0,0}, {0,0,4,0,0,0,0,0,0,0}, {0,0,0,5,3,0,0,0,0,7}, {0,0,0,0,0,0,0,0,0,0}, {0,0,2,0,0,0,0,6,0,0}, {0,0,0,7,5,0,9,0,0,0}}; int size;
Can you put up a program to solve sudoku?
ReplyDeletetry the program below this it should be better.
Deleteor
try this one:-(this is made using 3d array)
/*zero's out any possibles resulting from a cell being assigned a value, in all boxes*/
void BoxPossibles() { //
int box, c, col, lowcol, lowrow, n, r, row;
lowrow = 1; lowcol = 1;
for(box = 1; box < 10; box++) {
for(row=lowrow; row 9) {
lowcol = 1;
lowrow += 3;
}
}
}
/*zero's out all possibles for a cell with a value, in a column*/
void ColPossibles() {
int c, i, r, n;
for(c = 1; c < 10; c++) {
for(r = 1; r < 10; r++) {
if(A[r][c]) {
n = A[r][c];
for(i = 1; i < 10; i++)
PossAll[i][c][n] = 0;
}
}
}
}
/*zero's out possibles across the row, for any sqr assigned a value*/
void RowPossibles() {
int i, n, r, c;
for(r = 1; r < 10; r++) {
for(c = 1; c < 10; c++) {
if(A[r][c]) {
n = A[r][c];
for(i = 1; i < 10; i++)
PossAll[r][i][n] = 0;
}
}
}
}
# include
ReplyDeleteint check(int a,int b);
int check1(int a,int b,int c,int d);
void recursive(int x,int pos[82]);
void scaledown(int pos[82]);
int pos[82];
int q=1;
long c=0;
int ch[10]={0,1,2,3,4,5,6,7,8,9};
int ar[10][10]= {{0,0,0,0,0,0,0,0,0,0},
{0,8,6,0,0,2,0,0,0,0},
{0,0,0,0,7,0,0,0,5,9},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,6,0,8,0,0},
{0,0,4,0,0,0,0,0,0,0},
{0,0,0,5,3,0,0,0,0,7},
{0,0,0,0,0,0,0,0,0,0},
{0,0,2,0,0,0,0,6,0,0},
{0,0,0,7,5,0,9,0,0,0}};
int size;
void main()
{
int i,j,k=1,a;
int pos[82];
printf("WELCOME TO THE ULTIMATE SUDOKU SOLVER");
printf("\n\n\n");
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
if(ar[i][j]==0)
{
pos[k]=(10*i)+j;
k+=1;
}
printf("%d",ar[i][j]);
printf(" ");
}
printf("\n");
}
size=k-1;
printf("\n");
scaledown(pos);
k=1;
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
if(ar[i][j]==0)
{
pos[k]=(10*i)+j;
k+=1;
}
}
}
size=k-1;
recursive(q,pos);
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
printf("%d",ar[i][j]);
printf(" ");
}
printf("\n");
}
printf("%d",c);
}
void recursive(int x,int p[82])
{
c++;
printf("%d",c);
printf("\n");
ar[p[x]/10][p[x]%10]+=1;
if(ar[p[x]/10][p[x]%10]>9&&q<=size)
{
ar[p[x]/10][p[x]%10]=0;
q--;
recursive(q,p);
}
if(check(p[x]/10,p[x]%10)==1&&q3&&b<7)
{
if(check1(a,b,1,4)==0)
{
return 0;
}
}
if(a<4&&b>6)
{
if(check1(a,b,1,7)==0)
{
return 0;
}
}
if(a>3&&a<7&&b<4)
{
if(check1(a,b,4,1)==0)
{
return 0;
}
}
if(a>3&&a<7&&b>3&&b<7)
{
if(check1(a,b,4,4)==0)
{
return 0;
}
}
if(a>3&&a<7&&b>6)
{
if(check1(a,b,4,7)==0)
{
return 0;
}
}
if(a>6&&b<4)
{
if(check1(a,b,7,1)==0)
{
return 0;
}
}
if(a>6&&b>3&&b<7)
{
if(check1(a,b,7,4)==0)
{
return 0;
}
}
if(a>6&&b>6)
{
if(check1(a,b,7,7)==0)
{
return 0;
}
}
return 1;
}
void scaledown(int p[82])
{
int i,j,w,count=0;
for(i=1;i<=size;i++)
{
for(j=1;j<=9;j++)
{
ar[p[i]/10][p[i]%10]=ch[j];
if(check(p[i]/10,p[i]%10)==0)
{
ch[j]=0;
count+=1;
}
}
if(count==8)
{
for(w=1;w<=9;w++)
{
if(ch[w]!=0)
{
ar[p[i]/10][p[i]%10]=ch[w];
}
}
}
else
{
ar[p[i]/10][p[i]%10]=0;
}
for(w=1;w<=9;w++)
{
ch[w]=w;
}
count=0;
}
}