aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Brattlof <hello@bryanbrattlof.com>2020-08-08 19:30:23 -0400
committerBryan Brattlof <hello@bryanbrattlof.com>2020-08-08 19:30:23 -0400
commit0cbd8a6547a3825ff18e9b24b3493f3a2917a7c8 (patch)
tree2718f4c5b0378866a36500530ca788ae251a90c2
parentae541490bdd2dc592f21c2fbc5bdd196dddfafd3 (diff)
downloadsudoku-0cbd8a6547a3825ff18e9b24b3493f3a2917a7c8.tar.gz
sudoku-0cbd8a6547a3825ff18e9b24b3493f3a2917a7c8.tar.bz2
c: don't clobber the index we're checking
The inRow() inCol() and inBox() would clobber the 'i' index they where checking and returning a false true
-rw-r--r--c/sudoku.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/c/sudoku.c b/c/sudoku.c
index a71818b..5982f8f 100644
--- a/c/sudoku.c
+++ b/c/sudoku.c
@@ -12,7 +12,7 @@ bool inBox(int i, int n)
int boxCol = ((i % 9) / 3) * 3;
for(int j = boxRow; j < boxRow + 27; j += 9) {
for(int k = boxCol; k < boxCol + 3; k++){
- if(PUZZLE[j + k] - '0' == n)
+ if(PUZZLE[j + k] - '0' == n && i != j + k)
return true;
}
}
@@ -24,7 +24,7 @@ bool inCol(int i, int n)
{
int col = i % 9;
for(int j = col; j < 81; j += 9) {
- if(PUZZLE[j] - '0' == n)
+ if(PUZZLE[j] - '0' == n && i != j )
return true;
}
return false;
@@ -35,7 +35,7 @@ bool inRow(int i, int n)
{
int row = (i/9) * 9 + 1;
for(int j = row; j < row + 9; j++) {
- if(PUZZLE[j] - '0' == n)
+ if(PUZZLE[j] - '0' == n && i != j)
return true;
}
return false;