I am writing a Sudoku solver in C, but am having problems with how long it takes to run. It can solve easier puzzles but once I put in one a little more difficult it runs and runs and never stops.
int solver (int x, int y)
{
int a;
int b;
int i;
int j;
printf("Depth: %d\n", counter);
for (a=1; a<10; a++)
{
if (checkEverything(x, y, a))
{
board[x][y] = a;
counter++;
if (counter == 81)
{
return true;
}
if (counter > 200 || counter < -10) {
return false;
}
for (i=0; i<9; i++)
{
for (j=0; j<9; j++)
{
if (board[i][j] == 0)
{
if (solver(i, j))
{
return true;
}
}
}
}
counter--;
//printf("%d", a);
}
}
//printf("No Solution1");
board[x][y] = 0;
return false;
}
if ( board[x][y] = a; xxx;
? (The code requires a bit more than just formatting) \$\endgroup\$ – Aki Suihkonen Feb 28 '14 at 20:05