aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Brattlof <hello@bryanbrattlof.com>2020-08-08 19:38:20 -0400
committerBryan Brattlof <hello@bryanbrattlof.com>2020-08-08 19:43:24 -0400
commit789c5ff3f7abfd78558347627b1c7360f28eb911 (patch)
tree80a93be72e55863dd01dd129a38c65e2b1d340a3
parent0cbd8a6547a3825ff18e9b24b3493f3a2917a7c8 (diff)
downloadsudoku-789c5ff3f7abfd78558347627b1c7360f28eb911.tar.gz
sudoku-789c5ff3f7abfd78558347627b1c7360f28eb911.tar.bz2
c: rough working solver!
I don't understand why I need to return PUZZLE from the bool solve(). however doing so will output the solved puzzle.
-rw-r--r--c/sudoku.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/c/sudoku.c b/c/sudoku.c
index 5982f8f..3d5b2d9 100644
--- a/c/sudoku.c
+++ b/c/sudoku.c
@@ -33,7 +33,7 @@ bool inCol(int i, int n)
bool inRow(int i, int n)
{
- int row = (i/9) * 9 + 1;
+ int row = (i/9) * 9;
for(int j = row; j < row + 9; j++) {
if(PUZZLE[j] - '0' == n && i != j)
return true;
@@ -57,7 +57,7 @@ bool solve()
continue;
PUZZLE[i] = n + '0';
- if(solve(PUZZLE))
+ if(solve())
return true;
}
@@ -68,6 +68,8 @@ bool solve()
next:
i++;
}
+
+ return PUZZLE;
}