diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | solve.c | 76 |
2 files changed, 78 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..26714d9 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +-- links +https://www.websudoku.com/?level=2
\ No newline at end of file @@ -0,0 +1,76 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> + +int** create_sudoku(); +void print_sudoku(int** sudoku); +int calculate_square(int lin, int col); + +bool lines[9][10], columns[9][10], squares[9][10]; + +int main(){ + int** sudoku = create_sudoku(); + print_sudoku(sudoku); + + memset(lines, 0, sizeof(lines)); + memset(columns, 0, sizeof(columns)); + memset(squares, 0, sizeof(squares)); + + for(int i = 0; i < 9; ++i){ + for(int j = 0; j < 9; ++j){ + int val = sudoku[i][j]; + if(val != 0){ + lines[i][val] = true; + columns[j][val] = true; + squares[calculate_square(i, j)][val] = true; + } + } + } + +} + +int calculate_square(int lin, int col){ + /* + 0 1 2 + 3 4 5 + 6 7 8 + */ + return (lin/3)*3 + col/3; +} + +void print_sudoku(int** sudoku){ + for(int i = 0; i < 9; ++i){ + for(int j = 0; j < 9; ++j){ + printf("%d ", sudoku[i][j]); + } + printf("\n"); + } +} + +int** create_sudoku(){ + int s[9][9] = { + 2,0,0, 0,0,3, 7,9,4, + 4,0,0, 6,0,5, 0,8,0, + 0,0,1, 0,0,7, 0,0,0, + + 0,3,2, 0,0,0, 0,0,8, + 0,0,4, 0,0,0, 9,0,0, + 9,0,0, 0,0,0, 5,4,0, + + 0,0,0, 9,0,0, 1,0,0, + 0,4,0, 5,0,6, 0,0,7, + 3,8,5, 1,0,0, 0,0,9, + }; + + int **r = (int**)malloc(sizeof(int*)*9); + for(int i = 0; i < 9; ++i){ + r[i] = (int*)malloc(sizeof(int)*9); + + for(int j = 0; j < 9; ++j){ + r[i][j] = s[i][j]; + } + } + + return r; +}
\ No newline at end of file |