aboutsummaryrefslogtreecommitdiffstats
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/sudoku.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/c/sudoku.c b/c/sudoku.c
index 3d5b2d9..8d36d92 100644
--- a/c/sudoku.c
+++ b/c/sudoku.c
@@ -8,11 +8,13 @@ char PUZZLE[81];
bool inBox(int i, int n)
{
+ int inum = n + '0';
int boxRow = (i / 9 / 3) * 27;
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 && i != j + k)
+ if(PUZZLE[j + k] == inum && i != j + k)
return true;
}
}
@@ -22,9 +24,11 @@ bool inBox(int i, int n)
bool inCol(int i, int n)
{
+ int inum = n + '0';
int col = i % 9;
+
for(int j = col; j < 81; j += 9) {
- if(PUZZLE[j] - '0' == n && i != j )
+ if(PUZZLE[j] == inum && i != j )
return true;
}
return false;
@@ -33,9 +37,11 @@ bool inCol(int i, int n)
bool inRow(int i, int n)
{
+ int inum = n + '0';
int row = (i/9) * 9;
+
for(int j = row; j < row + 9; j++) {
- if(PUZZLE[j] - '0' == n && i != j)
+ if(PUZZLE[j] == inum && i != j)
return true;
}
return false;