Add ce Combn de merde

This commit is contained in:
lclerel- lclerel-
2026-03-05 18:58:08 +01:00
parent 9986e5a611
commit 5a0e7fb0dd
2 changed files with 60 additions and 1 deletions

View File

@@ -6,7 +6,7 @@
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/05 13:45:48 by lclerel- #+# #+# */
/* Updated: 2026/03/05 15:56:57 by lclerel- ### ########.fr */
/* Updated: 2026/03/05 16:49:26 by lclerel- ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_combn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/05 18:03:23 by lclerel- #+# #+# */
/* Updated: 2026/03/05 18:57:19 by lclerel- ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_put_tab(int *tab, int n)
{
int i;
char c;
i = 0;
while (i < n)
{
c = tab[i] + '0';
write(1, &c, 1);
i++;
}
if (tab[0] != (10 - n))
{
write(1, ", ", 2);
}
}
void ft_recursive(int *tab, int n, int pos, int start)
{
int i;
if (pos == n)
{
ft_put_tab(tab, n);
return ;
}
i = start;
while (i <= 9)
{
tab[pos] = i;
ft_recursive(tab, n, pos + 1, i + 1);
i++;
}
}
void ft_print_combn(int n)
{
int tab[10];
if (n > 0 && n < 10)
{
ft_recursive(tab, n, 0, 0);
}
}