Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int solve(int field[][COLS], int row, int col)
- {
- int n, m, i;
- if (row*col > 64) /* solved */
- {
- // output(field);
- return 1;
- }
- n = row;
- m = col;
- n++; /* set n, m to index of next cell */
- if (n > 8)
- {
- n = 0;
- m++;
- }
- if (field[row][col] == 0) /* use only empty cells */
- {
- for (i=1; i<=9; i++) /* search allowed number for the cell */
- {
- if (allowed(field, row, col, i)) /* is i allowed? */
- {
- field[row][col] = i; /* fill cell with i */
- if (solve(field, n, m)) /* continue with next cell */
- {
- return 1;
- }
- field[row][col] = 0; /* reset cell if no solution found */
- }
- }
- }
- else /* if cell is not empty, continue with next cell */
- {
- if (solve(field, n, m))
- {
- return 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment