diff --git a/ex08/ft_ten_queens_puzzle.c b/ex08/ft_ten_queens_puzzle.c index 5ef3e29..b705509 100644 --- a/ex08/ft_ten_queens_puzzle.c +++ b/ex08/ft_ten_queens_puzzle.c @@ -6,12 +6,11 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/30 17:05:04 by tosuman #+# #+# */ -/* Updated: 2023/04/01 02:15:31 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 02:17:57 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include -#include #define SIZE 10 void ft_putchar(char c) @@ -20,7 +19,7 @@ void ft_putchar(char c) } // print the current board and return sols+1 -int new_sol(int cols[SIZE], int sols) +int new_sol(int cols[SIZE]) { int i; @@ -28,7 +27,7 @@ int new_sol(int cols[SIZE], int sols) while (++i < SIZE) ft_putchar(cols[i] + '0'); ft_putchar('\n'); - return (sols + 1); + return (1); } int is_valid_board(int cols[SIZE], int col) @@ -50,20 +49,20 @@ int is_valid_board(int cols[SIZE], int col) return (1); } -int backtrack(int cols[SIZE], int col, int sols) +int backtrack(int cols[SIZE], int col) { int i; + int sols; if (col >= SIZE) - { - return (new_sol(cols, sols)); - } + return (new_sol(cols)); + sols = 0; i = -1; while (++i < SIZE) { cols[col] = i; if (is_valid_board(cols, col)) - sols += backtrack(cols, col + 1, 0); + sols += backtrack(cols, col + 1); cols[col] = -1; } return (sols); @@ -77,7 +76,7 @@ int ft_ten_queens_puzzle(void) i = -1; while (++i < SIZE) cols[i] = -1; - return (backtrack(cols, 0, 0)); + return (backtrack(cols, 0)); } /* ////