Unncecdseary sols param

This commit is contained in:
Timo Schmidt 2023-04-01 02:18:09 +02:00
parent f6b438c0f8
commit bfc1e60452
1 changed files with 9 additions and 10 deletions

View File

@ -6,12 +6,11 @@
/* By: tosuman </var/spool/mail/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 <unistd.h>
#include <stdio.h>
#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));
}
/* ////