From 6fe3c5c1886af8cd6c74b09ef2691b57c4aa41a0 Mon Sep 17 00:00:00 2001 From: damage Date: Fri, 24 Jul 2026 20:41:07 +0200 Subject: [PATCH] add step description --- sudoku.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/sudoku.c b/sudoku.c index 3df1ccc..c213fbb 100644 --- a/sudoku.c +++ b/sudoku.c @@ -27,6 +27,7 @@ int sudoku[9][9] = { */ // https://www.free-sudoku.com/sudoku.php?dchoix=evil +/* int sudoku[9][9] = { {VALUE_UNDEFINED,1,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED}, {3,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,8,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED}, @@ -38,6 +39,19 @@ int sudoku[9][9] = { {1,VALUE_UNDEFINED,VALUE_UNDEFINED,6,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED}, {5,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,8,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED} }; +*/ + +int sudoku[9][9] = { + {5, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 1, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED}, + {VALUE_UNDEFINED, VALUE_UNDEFINED, 4, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 1, VALUE_UNDEFINED, 2}, + {7, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 3, VALUE_UNDEFINED, VALUE_UNDEFINED, 5, VALUE_UNDEFINED}, + {VALUE_UNDEFINED, VALUE_UNDEFINED, 7, 3, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 6, VALUE_UNDEFINED}, + {VALUE_UNDEFINED, 2, VALUE_UNDEFINED, VALUE_UNDEFINED, 6, VALUE_UNDEFINED, VALUE_UNDEFINED, 4, VALUE_UNDEFINED}, + {VALUE_UNDEFINED, 9, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 8, 3, VALUE_UNDEFINED, VALUE_UNDEFINED}, + {VALUE_UNDEFINED, 8, VALUE_UNDEFINED, VALUE_UNDEFINED, 4, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 2}, + {4, VALUE_UNDEFINED, 6, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 7, VALUE_UNDEFINED, VALUE_UNDEFINED}, + {VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 1, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 9} +}; void readQ(int num) { printf("Enter every number of Q%d from left top to right bottom. Use `0` if on no initial value:\n", num + 1); @@ -225,9 +239,9 @@ bool isInQuadrat(int q, int val) { return false; } -void setValue(int q, int f, int val) { +void setValue(int q, int f, int val, char* rule) { sudoku[q][f] = val; - printf("=> setting %d in Q %d; F %d\n", val, q, f); + printf("=> setting %d in Q %d; F %d (%s)\n", val, q, f, rule); //printDumpSudoku(); } @@ -276,12 +290,14 @@ int main() { }; for (int val = 1; val <= 9; val++) { + // val is already set in quadrat, go ahead if (isInQuadrat(q, val)) { continue; } int possibleField = FIELD_UNDEFINED; for (int f = 0; f < 9; f++) { + // calculate row and col of current field in quadrant int row = calculateRow(q, f); int col = calculateCol(q, f); @@ -310,12 +326,12 @@ int main() { // found possible field? set val if (possibleField > FIELD_UNDEFINED) { - setValue(q, possibleField, val); + setValue(q, possibleField, val, "standard col/row check"); somethingChanged = true; } } - // check if only one field is left undefined -> hast to be the one special value + // check if only one field is left undefined -> has to be the one special value for (int f = 0; f < 9; f++) { // keep in mind that sudoku array might have changed since evaluation // -> ignore already set values @@ -324,7 +340,7 @@ int main() { } if (possbileVal[f] > VALUE_UNDEFINED) { - setValue(q, f, possbileVal[f]); + setValue(q, f, possbileVal[f], "every other value is not possible here"); somethingChanged = true; } else { // set to undefined, multiple or any other meta information @@ -336,4 +352,4 @@ int main() { printDumpSudoku(); checkSolution(); -} \ No newline at end of file +}