From f09bf30d08560cdd38b411ff057b895a57b8a0f4 Mon Sep 17 00:00:00 2001 From: azuminha Date: Thu, 3 Aug 2023 12:42:11 -0300 Subject: first commit~ --- README.md | 2 ++ solve.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 README.md create mode 100644 solve.c 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 diff --git a/solve.c b/solve.c new file mode 100644 index 0000000..d1f7114 --- /dev/null +++ b/solve.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include + +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 -- cgit v1.2.3