Compare commits

...

3 Commits

Author SHA1 Message Date
David Gailleton
a11db9327e 05 bonus 2025-12-16 15:25:34 +01:00
David Gailleton
0a617cc507 05 2025-12-16 10:57:14 +01:00
David Gailleton
63bb1bc416 04 bonus 2025-12-16 10:25:17 +01:00
14 changed files with 3061 additions and 0 deletions

27
04_b/aoc04_b.h Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* aoc04_b.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/15 16:15:37 by dgaillet #+# #+# */
/* Updated: 2025/12/15 16:33:20 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#ifndef AOC04_B_H
# define AOC04_B_H
typedef struct s_co
{
int i;
int j;
void *next;
} t_co;
t_co *new_co(int i, int j);
void co_add_back(t_co **lst, t_co *new);
void clear_lst(t_co *lst);
#endif

10
04_b/example Normal file
View File

@@ -0,0 +1,10 @@
..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@.

136
04_b/input Normal file
View File

@@ -0,0 +1,136 @@
@@@@@.@..@@.@@..@..@@@@.@@@...@@...@@.@@@@.@..@@....@.....@@..@@@@@@.@@.@@.@@.@@.@..@@@@@.@@@@@@@.@@@@@.@@@@@@@@@@@.@..@@@@..@@.@....@.@
.@@@@..@@@@@@..@.@@.@@@.@@@..@@@@@@.@...@@@@@.@@@@.@.@@.....@@@@@@.@@@@@.@@@@..@@.@.@@.@.@@.@@@@.@@.@@@@@@@.@@@..@@@@....@@@..@....@@...
.@@.@@....@@@..@.@.@@@@@@@@@.@@.@.@.@@@@..@@.@.@@@.@@@....@.@.@.@.@@.@..@@@@@@.@@@@@.@@@@.@..@.@@@@@.@@@@@@@..@@@@.@@@.@@@.@@@.@.@@@.@..
.@@@....@@@.@@.@@...@@.@@@@@@@@@@....@@.@@@@@@@@..@@.@..@@@.@.@....@...@@@.@..@@.@@@@@@..@.@@@@@@@@@@.@.@@@....@@..@@@..@@@@.@@.@@.@@@@.
@@@@@@.@@@..@@@..@@.@.@@@....@@@@..@@@.@..@.@@@@@@@@.@@@@.@.@.@@@@..@@.@..@@@@@@@...@@@.@@@@@@@.@@@@@@@..@@.@@@@@@@.@@.@@@@@@@.@...@@@@@
@@@..@.@@@@@..@@@....@.@@@@.@.@@@@.@.....@.......@..@...@@@...@@@@.@.@@.@.@@.@.@.@@@.@.......@@..@.@@..@@@@@@@@@@@@.@@.@@@...@..@@@@@.@.
@@@.@@@@.@@.@@@.@.@@.@.@..@@@@@@@@..@@@@@.@..@@@@.@@@..@@..@@.@@@@@@..@@@@@@@@.@.@@@.@...@.@.@@@@@@...@@@@.@@@@@@@..@.@@.@.@@@@@@@@@.@@.
@@...@@@@...@@@@@@@@@.@@@.@@@@..@@@@.@@@@@@.@.@.@.@@@@@.@@@@@.@@@@@@@@.@@..@.@.....@.@@@@@@.@@@.@..@@.@@@.@@@..@.@@@@...@@@@.....@@@.@@.
@.@@@.@.@.....@@.@@.@@@@...@@@@...@@@.@@@@@@@@@@@@@@.@@@@@@..@..@@.@@@@@..@@.@@@.@@@..@.@@@@@@.@@..@.@@@.@@@@@@@@@@@.@@@@@....@@@.@@@@@@
@@@@@@@@@.@@@@@@@.@...@.@..@@@..@..@@..@@.@@.@@@.@.@@@@@@@@@@@.@.@.@@@@@@.@@@.@@.@@@@.@.@@@@@@@@@..@@@@@@.@...@.@.@@.@.@@@@@@.@@@@@.@.@.
@@@...@.@@@@....@..@@.@@@@.@.@@.@@@.@.@...@@@@@@@@..@@@@.@@@@@@@......@...@..@@@@@@@@@@.@@.@@@@..@@@@...@@.@..@@@.@..@@@.@..@@@@@@@@.@@@
@@.@..@@.@@@.@@..@..@@@.@@@@@.@@@@@@@@@@@@@.@@..@@..@.@.@@@@.@.@..@@..@.@@.@@@.@@@@@@@@@@@@@@@.@@..@@@@@@@@@@@@@@@@@@.@@.@.@@@@..@@.@@@.
@@@@.@.@@.@@@@@@@@@@.@@@.......@@@@.@..@@.@.@@@.@@@.@@.@.@@.@.@@@.@@@.@.@@@.@@@@@@@@@.@..@@.@@..@@@@@@@@.@.@@..@@@.@@@.@@.@@@@.@@@@.@.@.
.@@@.@@.@..@@@@.@..@@..@@.@@.@@@..@@@@@.@.@@@.@@@@@@@@.@@@..@@@..@..@@@@@.@@@.@@.@@.@..@@@@@.@@@@@.@@.@..@@@@.@.@@..@@.@@@@.@@.@@@@@@@@@
@@.@.@@.@.@....@@@@..@.@@@@@@@...@@@@@.@@...@@@.@@@..@....@@.@@@.@.@@..@.@@@..@@@.@.@@@...@.@@@@..@@.@@@.@..@@@@@..@@.@@@@@@@@.@@@@@@@..
.@.@@.@@@@.@.@@.@..@......@.@.@.@.@@@.@@@.@@@@.@@@@@.@@@@@@@@...@.@.@.@.@.@.@@.@@@@@@@@..@@@@.@@@@@..@.@@.@@.@@.@@@@@@@@.@.@.@@.@@@@..@@
@@@.@@@@@.@@@.@.@@.@@.@@@..@.@@.@@@@..@.@..@@@@.@@@@.@@@.@@.@@@.@@@@@@@.@@@@...@@@@..@...@@.@@@@@@@@@..@@@@@@@@@@@.@@@@@.@@@@@@..@@..@@@
@.@@@@@.@@@.@@.@@@.@@..@.@@@.@@@@@@...@..@@@@@@@@@.@@@@@@@@@@@@@@@@.@@@@@.@@@@@@@@@@@@.@.@@.@@...@.@@.@.@.@@@.@@@..@@@@@.@.@@@@@..@..@..
@@....@..@.@@.@@@@@@@.@@@.@@@@@.@@.@@.@....@@..@@.@.@@.@@.@@@@.@.@@.@@@@..@@@@@@.@@..@@@@@.@@@@@.@.@@@@...@@@@.@@@@@@@.@@@@@@@@@@..@@@.@
@@@@@....@...@@@.@@@@.@@.@.@@@@@...@@@@.@.@@..@@.@@@@@.@@.......@..@@@@@@..@@...@@@.....@.@@@@.@@@@..@@@..@@.@@@..@.@.@.@@@.@...@..@@@@@
...@@@@@@..@@@..@@@@.@.@@@@@@.@.@@@...@.@@@.@@@@@@@@@.@@...@@.@@..@@@@...@@@@.@@.@@..@.@@.@@@.@@@@@@@.@..@.@...@..@.@....@@@..@@@@@@@@@@
@.@@@@@...@..@@@.@@@.@.@.@@@.@@@....@.@@@.@@..@.@@@@@@.@@..@@@@@@..@@.@@.@.@@@..@.@..@@..@@@@@@@.@.@@@.@@@.@.@@..@@@@@@@@@@@@..@@..@@.@.
@..@..@..@@@@@..@@...@@.@@@@.@@.@@.@.@@@.@@..@@..@@@..@.@@@@..@@@@.@@@@.@@.@@@.@@@@@@@...@@.@@..@.@@@@@@.@@@@@@.@.@.@.@.@@@.@..@.@@.@.@@
@@....@@@@@..@@@@@.@@@@@@...@@@@..@@@..@@@@@@@..@.@@@@@@@@.@.@@@@@@@@@@..@.@...@.@.@@..@@.@.@@.@@@@.@@.@@@.@@@..@@...@@@.@@.@@@@.@.@@@.@
.@@@.@@.@.@.@@@.@@@@@@@.@.@@@.@@@@@@@@.@...@.@..@@.@@@@@....@@@...@.@..@@@@.@.@@.@..@@@@@@@@@.@.@@@.@@..@.@@.@.@@@@@.@@@.@@@@@.@@.@@.@@@
.@@@@@.@.@@@@@@.@..@.@.@.@@@@....@@.@..@@.@@...@@.@@.@@@..@@@.....@@@.@@...@.@@.@@@@..@@@@.@@....@@..@.@.@@.@@@@@@@@.@@@.@.@.@.@@@@@@..@
...@@@.@.@@.@.@@.@@@@@@@.@@..@..@@..@@.@@@@@.@@@@..@.@.@..@@.@..@.@@@@@@@.@.@@@@@.@..@@@@.@@.@...@..@@@@@@.@@@@@@@@@@@..@@@@@@@@.@.@@.@@
@@@...@@@@@...@@..@.@.@@.@@@@..@@@.@@@@.@@@.@@@@@@@@@.@.@..@@@.@@@@@@@@.@.@@@@@@.@@@...@.@.@@@@@..@@@.@.@@.@@@.@..@@@.@@@@@.@@.@....@.@@
@@.@@@@..@.@@@@@@@.@.@@@@@@@..@@.@@...@@@..@@@@@@@@@.@...@@@@.@@...@@@@@.@.@@@@..@.@@@@...@@.@@@@...@@@.@.@@@.@@.@.@@@.@@.@@...@@..@@@@@
.@@...@@@@@@.@.@@@.@...@@@@@@..@@@@@.@@.@@@@@@@@@@@@.@@@@@.@.@@..@@@@@.@@.@..@@.@.@@@.@@@..@..@@@.@.@@@@@.@.@@.@@.@.@@.@@@..@@@@@.@@@@@@
@@..@@@@@@.@@.@@@.@@@@@@.@@@@@...@..@@@.@@@.@.@..@.@@@.@@@.@@@@@@.@@@..@@.@..@..@.@@@@@.@...@@...@@@@.@@.@.@@..@@@.@.@@.@.@@@@.@@...@.@.
@.@.@@.@@@.@.@@@.@.@@@.@.@...@@@.@@...@@.....@...@@..@.@@.@.@@@@@@@.@@.@@@@@@@.@.@@@.@..@.@.@..@@@@.@@.@.@.@.@@@@@@..@.@@.@@@.@@@..@@..@
@.@.@@@@.@@@@..@..@@.@@@@@@......@@@..@@..@.@@@@@.@@@@.@.@.@.@..@..@.@...@@@@@@.@.@@@@.@@.@@@@@.@.@@.@@@@@...@.@@@@@.@@@@@.@...@@.@@.@@@
..@@.@@.@@@@..@....@@@@..@@.@.@.@@@@.@@.@@@...@@@.@@..@....@@...@@@@.@@@@@....@@@@.@@.@@@@.@@@...@.@@@.@@@@.@@@....@.@@.@@.@...@@..@@@@@
@..@@.@@.@.@@@@@@.@@@@@@.@..@@@@.@.@@.@.@@.@@...@@@@@@.@@@@@...@@@@@@...@.@@@@@...@@@..@..@@@@.@@.@@.@@@@..@@@@@@@@@@@@@@.@@.@.@@.@.@.@@
@@@@.@.@@@.@@.@@.@@@.@..@...@@.@@@.@@@@@...@.@@@.@@@..@.@.@.@.....@@@@@@.@.@@@.@@.@@....@.@..@@@.....@@.@@@..@@@..@@.@@@.@@@.@@.@@@...@@
...@..@@.@..@@@@@@@.@@@.@@@@.@.@@@@@@@@@@@@.@@..@.@@@@@.@@@@@@@@.@@.@...@@.@@@@@@@.@@@@.@..@...@.@@@@..@@..@@.@@@.@.@...@@...@..@.@@@.@@
@@@@@@.@@.@.@.@@@.....@@@@@@@..@.@@@....@@@.@.@@@@..@@.@@@@...@@@@@@..@@@@.@..@.@.@@@.@.@@@@@.@@@@@@@@@...@@.@@@@@@@..@@...@@@@@@@.@.@.@
@@@@.@@@.@@.@.@.@@@@@@@@@.@@@@@...@.@.@@@.@@..@@@@@@@@@@@.@..@@..@@@@.@@..@@@@@@@@@@.@@..@....@@@@@@@@@.@...@@@@@.@@@.@@@@@..@@@.@@@.@@@
@.@@.@@..@@....@@.@@.@@@@@.@@@@@@@@@@@@@@..@@.@@@....@..@@@@.@..@.@@@@@@@@@.@@@...@.@@.@@...@@..@@..@.@@@@.@@@@.@.@@.@.@@.@@@@@@@@@..@.@
.@@@@@.@....@@.@.@@.@@@@@.@@.@@@@.@.@@.@.@@@.@@..@.@@@..@@.@..@@..@.@@@@@.@.@@@@..@@@@@...@@@.@.@@@@@@@@@@.@@@@.@@.@@@@..@@@.@@.@@@@@@.@
..@..@@@@@..@@@.@@@@@.@@@...@@.@@@@..@@@@@@@..@@@@.@@.@.@@.@@...@@..@@@.@@.@.@@@@...@..@@.@@@..@@..@.@@@@@@..@@@.@@@.@@.@@.@@@@...@.@@@.
@@@@@@@@@@@@.@@@.@@...@@@.@.@@.@@.@@.@.@....@@@@@.@.@@@@@@@@.@.@.@@@.@@@..@@@.@.@@...@@..@@@.@@@.@@@@@@@..@@@@@@@.@.@@@.@.@@@@@...@.@@@.
.@@@.@@.@..@@..@@.@@@.@@.@.@@@.@@@@@.@@@@@@@@.@.@.@@.@@@@@..@...@@@.@.@@@@@@@.@.@..@..@...@....@.@..@@@@@.@@@.@..@@@@.@@@.@.@@@@...@.@@@
..@@@..@@@@..@@@@.@@.@@@.@.....@@@@@@@@@.@@@@@@.@@@@@..@...@@@@@@@@@.@@.@@@@@@@..@@@@@@.@@.@@@@@.@.@@@@@@@.@@@@@@@@@..@@..@.@@@..@@@.@@@
@@@@@.@@..@..@.@..@.@@@@@@.@@@@@@@@.@@@@@@@@..@@.@..@@@@@@@@.@@@@@@...@@.....@.@@@@@@....@..@@.@..@.@@.@@.@@@.@@@@@@@.@@...@@.@@@@@@@@@@
.@.@@...@@.@.@.@@.@@@@@@@@@.@.@@@...@@..@@.@@@@.@@@@@@@@@.@@@@@@@@@...@...@@@@@.@@@@@@@@@@@@@.@@@@@@.@@@@@@@.@.@@@@.@.@.@.@.@@@@@.@@@..@
@..@@@@@.@..@@@@@@@.@@@.@@.@...@@@.@@@.@@.@.@@@.@@@@@@@.@...@@@..@@@@@@@..@.@.@..@@.@@..@@@..@@.@.@@@@@@@@.@@@@.@.@..@@.@@@@..@@@@@@@@@@
@@..@@.@@@@@@@@@@@@@.@.@.@@@.@@@@@@@.@@@@@..@.@@.@..@@@.@.@.@.@@.@...@.@@@@..@@@@.@.@.@@.@..@.@@.@@@.@@@@@.@.@@@.@.@@@@@.@.@.@@.@@@...@@
@@@.@@@.@@@@@.@...@.@@@@@.@@..@..@@@..@.@.@@@@@@......@.@@.@@@@@@..@@@@@@@@@..@..@.@.@@.@@@@.@@@@.@..@@@..@@...@@@.@@@@@@.@.@......@.@@@
@@@..@..@...@@@@@@@@@@.@@@..@.@@..@@@.@@@@.@@..@@@@@..@.@..@@@@.@.@.@..@@@.@@.@.@@.@...@.@@@@@@.@..@@@@@@@@@@@@@@@.@@@@@.@@.@@@@@.@.@@..
..@@@.@@...@@@@@..@@.@@.@@@@@@@@.@@@@@@...@@....@@...@@@@@@@@@@@.@@.@@@...@@@.@@@@.@.@@@@.@@.@@@.@@@@@@@@@@..@@.@..@@.@@.@@@@.@.@@.@...@
.@@.@@..@@@@@.@@..@@@@@@.@....@.@@@@..@.@..@.@@@...@@@.@.@@@@@@@.@.@@.@@.@@.@@.@@...@@@@@@.@@@@.@.@@@@@@@@...@@.@@@.@@.@@@@@.@...@@@@@@@
.@@@@.@@@@@.@@@.@@.@.@.@@@.@.@.@@..@@@.@@...@@.@@.@@.@@@.@@@@@@.@.@@@.@..@..@@.@..@@@@@.@@.@.@@.@@.@..@@.@..@@@@.@@..@@@.@@@@@@@@.@.@..@
@@.@....@@@.@@.@@..@.@.@.@.@.@@..@@@@@.@@@..@@....@@.@@@..@@@@@..@.@.@@@@.@@@@.@@@@...@@@..@@@@@@.@..@@@.@@@@@@@@@@@..@@..@@@@.@@.@.@..@
..@.@@.@.@@@....@@@.@.@@@@@@@@@@.@@@...@.@@.@@.@@@@@@@.@.@@@@@@@@.@...@@@.@@@@@..@.@@.@..@.@@@@@..@@@@@@@@@@..@@.@@@@.@@@@@@@@@@...@..@.
@@..@@.@@@@@@@..@@..@@@@.@.@.@@.@.@@@@.@@@.@.@@..@....@@@.@@@....@@.@@@.@@...@@@..@@.@@...@@@.@@@....@@@.@@@.@@@@..@@..@.@@.@@..@@@.@@@@
@@.@.@@@@@@@@@@@@@..@@@..@@.@@@@@@@@@@@@.@..@.@@@@@.@.@@@..@@.@@@@@...@@..@@@..@...@@.@..@.@...@@....@.@@.@..@.@@@@@@.@@@.@.@@.@.@@.@@..
@.@.@@@@@@@@@@..@..@@.@.@@@@@@@@.@@..@@@@@.@@@@@.@..@..@@@.@@@.@@@@.@.....@@@@.@@@@@@@@@@.@@@@@.@@@..@@@.@@@..@.....@@...@..@.@@@..@@@@@
....@@@@.@..@@@.@@@@...@@@@.@.@.@.@@..@....@@..@@@.@....@@@.@@@..@@@@@....@..@@.@.@.@@.@@@.@..@@@@.@....@@@@@@.@@@@..@.@@.@.@@.@.@@@.@.@
@.@...@@@@@@@@@.@@@@@@.@.@.@@@..@@.@.@.@@@@@@.@@....@.@@..@.@.@@@@.@@@@@@.@@@.@@.@..@@.@.@@@...@@@.@.@@..@.@@.@.@.@@@@@@@@.@@@@@...@@@@.
@@.@.@@@@@.@@@.@@@.@@@.@@@..@@@.@.@.@@@@.@..@@@@.@@@@@@@@@.@@...@@@.@@.@..@....@@@@@@@.@.@@@@@@.@@..@.@@@.@@@@@@...@.@.@....@.@.@@.@@@@.
@@@.....@..@@@@.@.@@@@@@@...@.@@@.@@@.@@.@@@@@@...@@.@.@@@...@@@@@@@..@@@...@.@...@@@@@.@@..@...@@@@@.@@@.@.@@@.@@..@.@@..@@@@@@@.@.@..@
@@@@@@@.@.@@..@@@@@@@@@...@.@.@@@@.@..@.@.@.@@.@@.@@..@@@.@@@@@.@@@@@.@@@@.@.@@.@@.@.@@..@@@@..@..@@@@@@.@.@@@@@...@@.@..@..@.@@.@.@@..@
@.@@@@@@@@..@@...@@@.@@@@..@.@@@@@@...@.@@.@@@@@@.@@@@.@@..@.@.@@..@@..@@.@..@.@@..@..@@@@...@@@.@@.@@.@@.@@@@@..@@@.@..@.@@.@@@@@@...@.
@@.@.@@@@@@@@@@@@..@@@..@.@@@.@.@@@.@@@@...@@@@@@.@.@@@..@@@@@@@.@.@@@@@..@@@...@@@..@@..@...@@@@@..@@..@.@@.@.@@@@@@@@@@.@..@@@.@@@@.@.
..@@...@@@@@@@.@@.@.@@@@@@@..@@.@@@@..@@@@.@@..@@@.@@.@@.@@.@@.@.@@@..@...@.@@@@@.@@@@@@@@.@.@..@@@@@.@@.....@@@@..@@.@@@.....@@@@@..@@.
.@.@@@..@@@.@@@@@@..@@@@@@..@....@@@@@.@@@@@@.@@@...@@@@...@..@@.@@@@@@@@@@.@.@@@.@.@@..@.@@@@.@@.@.@..@.@@@@@@@..@@@@@@@@@..@.@....@.@@
@@@@@@@@@..@@...@@@@.@@@@.@....@.@@@@@@.@@@@@@@.@@.@.@@.@@@..@@@@@@.@@.@@.@@@@@@...@@@@@@@@@.@@@@..@@@..@..@..@@.@.@@@.@@@...@@...@..@@@
@@@..@.@@@.@@@..@.@...@@.@@@...@.@@..@.@@@@@@.@....@@.@@.@@@@@@@@.@@@@@@..@@.@.@.@@@@@..@..@@@.@.@..@@.@@...@.@@@@@.@..@@..@...@@.@@@..@
@..@@.@@@@@@.@.@@..@.@@@@@.@@@@@@@.@.@@@.@..@@@@@.@@@@@@@..@.@@@@@...@@@.@@.@.@@.@..@.@..@@@..@@@@@@@@@@@..@@.@.@@@@@.@@@..@@@......@@.@
.@@.@.@@@.@@.@.@@@@..@@@@@@..@..@@@@....@.@..@@.@@@@..@@@@.@@@@@@@@@...@.@@.@@@@.@@@@@@@@@..@.@@@@@@@@@@@@@@.@@@..@@.@@.....@@@@@@@@@...
@...@@@@.@@@@.@@@.@...@.@.@@.@@..@@..@..@@@@..@.@@.@@@.@@@@@@@@.@@@.@...@.@....@.@@.@@.@@.@..@@.@@.@@.@@.@@@@@.@@@@.@@@@@.@@.@@@@@..@.@@
@@@@@@@@..@@...@@..@@.@@@.@.@.@@@..@.@@@.@.@.@@@.@@@.@@...@@@@.@.@@@@@@@.@.@@@.@@.@@@.@@.@@@@@@.@.@@.@.@.@@@..@@@@.@@@@@@@....@@.@@...@@
@@@.@@@@@@@@@@@.@..@.@....@@@@@.@@@@@..@@@@.@@......@@@@@@@.@.@@@.@..@@@@.@.@@@@@.@@@.@..@.@@...@.@.@.@@.@...@..@@@..@@@.@..@@@@.@..@@@@
...@@.@@@.@@.@@@@@..@@..@@.@@...@.@@.@..@.@@@@.@@@...@..@@@@@@@@@@@@@.@@@@.@.@.@@.@@@.@.@@@@.@..@@@@.@.@@.@@.@@....@@..@@@@...@@@@@.@@.@
@@@@@......@@.@@@.@@...@@@@@@@.@.@@@....@@.@..@@.@@.@@@@@@@@@@@@..@....@@.@.@@.@@@@@@@@.@.@@@.@.@.@@@@@@@@@..@@@@.@...@.@@@@@@@..@.@..@.
@@@.@@.@.@@@@.@@@.@@@.@@@@..@..@@@@.@@@.@....@@@@@.@.@@@@@@.@.@@@@@@...@@..@@@.@@..@..@..@.@..@@@@.@@@@@@@@@@@.@@@.@@@@.@.@@@.@@...@..@.
...@.@@@.@.@@.@@@@@...@@.@@@@....@@@@@@@@@@@..@@.@..@@...@..@@.@@@@.@..@.@@@....@@@@.@@.@.@@@@@@@...@.@@..@.@@@.@@@@@..@@@@@.@@@@@@@@@@@
@@.@@@@@@@....@..@@@@@...@@.@@@@@....@.@.@@.@@@.@@.@@@@@.@@@@@@@@@@@.@.@@.@@@@@..@.@@@@@@@.@..@.@.@.@@@@..@@@@@@.@..@@@..@..@@@...@@.@..
@@@..@.@@@.@...@@@..@.........@@.@.@@@@.@..@@@@@@@@.@@@@.@@@@@@@.@@..@..@@@..@.@@@...@@@..@.@.@@@@.@.@@..@@@@.@..@@.@@@@..@@@.@@.@..@@..
@.@@@@@..@@@.@@.@.@@.@@@@@@@..@.@@.@.@@@..@.@@@.@@@@@@.@@@@@..@@.@@..@@@@@...@@@@.@@@.@@@..@@.@@@@@..@@@@@.@@@@.@...@.@.@.@..@@@.@@@@@..
.@@@....@@...@.@.@@.@.@@@@@@@@@@.@.@..@@.@@.@@....@..@@.@..@@@.@@@@@@.@@@.@@@@.@@..@..@.@..@@@@.@@@.@@@@@@@.@@@@.@@@@@@@@.@@@@.@@@@.@.@@
@@@@@@@@.@@@.@.@@@@@@@.@......@@.@@@.@..@@@.@.@..@@.@@.@.@.@.@@.@@@@.@@@@@.@.@@@.@@.@.@.@@@@.@@..@@@.@@..@@@@.@@@@@..@@@.@@@@.@@.@.@@@.@
@.@@@@..@@@@@...@@@@.@..@@@@@.@.@..@@.@@@....@..@@@....@.@@@..@..@@.@@@@..@@@@@@@...@...@@.@@@@@@..@@@@@@..@@@@@@@@.@@@.@@@@.@.@@.@.@@@@
@@.@@.@@.@@@@@.@.@@@.@..@@..@@@@@..@@@@@@@@@..@..@@@..@@@@@.@@..@@@@@@...@.@@@..@@..@@@.@@.@@@.@..@..@@@.@@..@@@@.@@@@@@.@.@..@@@..@.@.@
.@@@@@.@@@@@.@@@@@@@@@@@@.@@.@@....@@.@@.@@@@@@.@.@@@.@.@.@.@@@@@.@....@.@@.@@.@@.@@@@...@@@.@..@..@.@@@@@..@.@..@@@@@@@@@@@@@@.@@@@...@
..@..@@@.@..@@..@@@..@@@.@..@.@@@.@@@@@@.@.@.@@@@@..@@@@@.@..@.@@.@@@.@@@@@..@@@...@@@@.@@@@@@.@.@@@@.@@.@@....@....@@......@@@@@@..@@..
@@@@@@@.@.@@@@.@.@@.@@@@.@.@@@@.@.@@@.@@@@@@.@@@..@@.@..@@..@..@.@.@.@@@.@..@@...@.@@.@@@@.@...@.@@@@.@@..@@@@@@@.@@@@.@@@@@..@@@.@@@...
.@@@..@@@@.@@@.@@@@@.@@@...@..@..@@@@@..@.@@@..@@@@.@.@@@@.@@@.@.@@@.@@@@@@.@@@@..@@@.@.@.@@@....@@@@@@..@@@.@@..@.@@.@@..@.@@@@@@.@@@@.
@@.@..@.@@@@@.@@@@@@@@@.@.@@@@@@.@.@.@@...@..@..@.@@@@@@@@@@.@.@@.@...@..@.@.@@..@@@.@..@@@@..@@..@.@.@@@@@@.@.@.@@@@@@@..@.@@@@.@@@@@@@
.@..@..@@.@@...@.@@@@@@@.@@@@@@.@@.@@.@...@..@@@.@..@@@@..@...@@@.@..@.@@.@@@.@@.@.@@@@..@...@.@.@@.@@..@..@@.@@@.@...@@..@@@@@@..@@....
@@@..@@@@@@@.@@.@@@@..@..@@@...@@@@@@@@@.@.@..@@@..@@@@.@.@....@..@@@@@..@@@@@@@@@.@@@.@..@@@@@@..@@@...@.@@@@@.@@.@.@.@...@@@.@.@@..@@.
@@@.@.@@@@....@.@@@.@@@@@@@@@@@@@@@.@@.@.@@@@@@@@@.@.@@.@@.@@@.@@.@@.@@@@@@@@.@@.@..@..@@.@@.@@@....@@..@@@@@@@@@@....@@@@@..@@.@@.@@@@.
@..@@@@@@@@@@..@@..@.@.@.@@@@@@@@@@@@.@.@@.@@.@@..@.@@@@@.@@@@@@@@.@@@..@.@....@@..@@.@..@..@@@.@.@..@.@..@@@@@@@@@@..@.@.@@@..@@@@@@.@.
@@@@@.@@..@@@@@@@@@@@.@@@.....@.@@....@@@.@@@@.@.@@@@.@.@@.@@....@@.@@@@.@@.@..@..@@@@@..@@@..@@..@@@@.@@@.@..@@.@..@@...@@@@...@@@@.@@@
@@.@..@@..@...@@@.@.@....@@..@@@@.@@@@..@@@.@@@.@@@..@@@@..@@@@@@@@..@@@@@@@@.@..@....@.@.@@@@@@.@@@@@....@@@@@....@@@@.@@@....@@.@@.@@@
@@.@@@@.@@..@.@.@..@@.@...@@..@@@..@@@@..@@@@.@@.@..@...@.@@@@.@@@@@@.@...@@@....@@@@.@.@@..@@.@@@@@@@..@..@@.@@@@@@@@@@.@.@.@@@...@.@@@
.@..@@@@@..@@@@.@@@.@@..@@@@..@@@.@@.@..@.@..@@...@@.@@@@@@@.@@@@@@.@@.@@.@@@@@@@@@@..@...@@.@@@@..@@@@.@@.@@.@..@...@@@@...@.@@@@@..@@@
....@@@..@.@@@@@@.@@@@.@@@..@.@.@@.@@@@..@@@.@@@@.@.@@.@@..@..@@@......@.@@@@.@@.@.@.@@..@.@....@@@.@@.@@@@....@@@@@.@.@@@..@..@@.@@@..@
@@@@@.@.@@@@@..@@.@@@.@.@@@@.@...@@@.@.@@@@@@@@@@@@@..@@@@@..@@@@@.@.@.@@.@@@..@@@@...@..@@.@.@@@.@@@@@..@.@.@@@.@.@.@.@..@@@@..@.@@@@..
.@.@.@@@.@.@@.@@@.@@@@..@.@@@@..@.@@@.@@.@.@.@.@@@@..@@@.@@@@.@@@@@@@@@.@.@@@@@.@.@.@@@@@.@.@@.@.@@@.@@.@.@..@@@.@@@@@.@@@@@@@@..@@@@@@@
@..@@..@@..@..@@@.@@.@@.@@@.@.@@.@@@@..@@.@...@@.@@...@@@@..@.@.@...@.@.@.@@@@@@@@@.@@@@@@@@.@@.@@..@.@.....@...@@.@@.@@..@@@@...@@@@@@@
@@@.@@.@@@..@@@.@@@@@@.@@@.@@@.@@.@@@.@@.@.@..@@.@@...@@.@@.....@.@@@@.@@@.@.@@@@@.@@..@.@@@@@@.@.@@@@.@@.@..@@@@..@@@@.@@@@..@@@@@..@@@
.@..@@@@@@@@.@@.@@.@.@@.........@@.@@.@@@..@@..@@.@.@.@..@@@@.@@@@@@.@@@..@@@.@@@@.@@.@@.@@..@@@@@@@@.@@@@...@@@@@@...@@@@@.@....@@@@@@@
@@.@.@@@.@.@@...@.@@.@@@.@@@@@.@..@@.@@@.@...@@@@@@@@.@@@.@@@@@@.@@@.@.@.@@@.@.@@@@..@..@@..@..@@.....@..@@....@.@@@@@@.@@@@@@.@@.@@@@@.
@..@@@@@@.@.@@@@.@.@@.@@.....@.@.@@@.@@@.@@@....@.@@@.@@@.@@.@@@@.@@.@@.@@@......@@@.@@@@@@@@...@@@.@.@@@..@....@.@.@.@@.@@.....@@....@@
@.@@@.@@@@@.@@.@.@...@@.@@@@@.@@@@.@.@@.@@...@@.@@@@@@@@@@@@@@@@.@@.@@@@@@@.@@@@@@..@@@@@@@..@.@@.@..@.@.@@@@@.@@@@@@@@.@@@@.@@@@@@@..@.
@@.@.@@@@....@.@.@@@@@@.@@..@@@@@@@.@.@.@@@.@@@@@...@.@@....@@.@@.@@@@@.@.@.@@..@.@.@@@..@@.@@@..@@@@@@.@@@@@...@.@@@@@.@@@@.@@.@.@.@@@@
@.@.@.@@@@@...@.@@.@@.@@@@@...@.@@..@@.@.@@@.@.@..@@.@@.@..@..@@@@@@@@@.@@@....@@..@.@@.@.@.@@@.@..@@@@@@@@@@.@.@@..@@.@@@@@@@@@@@@.@@.@
.@...@@@.@@.@@@.@@@@@@@.@@@@@@.@.@@.@@.@@.@@@@.@....@..@...@@.@@@@@@@.@@@@@@@@@@@@.@@@@@@...@@@@@..@@@.@.@..@@@@@.@@@...@@@@@.@@@@@@@@@@
.@@..@.@.@@.@@.@@@@@@@@.....@.@@.@..@@@.@@.@@.@@@@.....@.@@@@@.@@@..@.@@....@.@.@@..@..@.@@@..@@.@.@@.@@.@@@@.@@@@@..@@@@@@@...@@.@.@..@
.@.@@..@@@@@....@@@@@@@.@..@.@@@@@..@.@.@@@@@@@@@.@.@@...@.@@.@.@@.@@.@@@@@.@..@..@.@.@@@@@@@...@..@@@@@@@@.@@@@@.@.@.@@@@@.@.@.@.@.@@@@
@.@@@.@@@.@@@@.@@@@@@.@@.@@.@.@@..@...@@..@.@.@@..@@@.@.@@.@@@.@@@...@@@@.@..@@@.@.@@..@@@@@@...@@.@@@@@.@@.@@...@.@.@@.@..@@......@@@.@
.@@..@@@@@@@@@...@@.@@@@@@@.@@@@..@@@.@.@@..@@.@.@.@....@@@@@@@@.@@@.@.....@@@@...@@.@@.@.@@.@..@@@.@@@@@@@@@...@.@.@.@@@@.@@@.@@@.@@@.@
@@@...@..@@@@.@@.@@@@@.@@@@@..@@@@@@@@@.@@@..@@..@@@@.@@.@.@...@.@.@@@@@@@@@@..@@@@@@.@@...@@.@..@@@@@.@@@@@@@@.@@...@@.@.@@.@@@..@@.@@@
@@@.@@@@@@.@@.@.@@.@@@.@..@.@.....@@@@@.@@....@@.@..@@@@@.@@@..@@@..@@.@@@.@@@.@@.@@@@@@.@.@@@..@@@@.@@@..@@@..@@@.@@@....@.@@@.@...@.@.
@.@@.@@@@.@@@..@.@@@.@@.@@...@...@@..@@@@@@.@@.@@@@@@@..@@@@@@@@@.@.@@.@@@@@@..@@..@.@..@.@@@@..@@@@@@@@.@@@.@@@@..@.@.@@.@@.@@@@@@.@@@@
@..@@...@.@.@@@.@.@.....@..@.@@..@.@..@@@@.@@@..@@.@@@..@@.@@..@.@...@..@@.@..@@@.@@.@@@.@@@.@@.@@@@.@@@.@@@@.@...@@@@@.@@@@@..@@@@.@..@
.@.@@@.@@.@@.@@.@@@.@@@@@@@@..@@@...@.@@.@@.@@.@@@@@@@@.@.....@.@.@@@@@@@.@.@.@@@@@.@@@@@@@@@@@@@.@@.@@..@.@...@.@@@..@@@.@@.@.@@.@.@..@
@@@..@@@.@@@@@@@@@@.@..@@.@@@.@@@@@@..@@..@@@.@.@....@@@@@@.@@@@@@@@.@@...@@@..@@...@@@..@.@@..@@@@@..@@@@.@@@.@.@@@@...@..@.@.@@.@@.@..
..@@.@.@.@@..@...@..@...@@@.@@@@@@@@@..@@@@@@..@@@@.@@@@.@@@@...@@@@@@@@@@.@@@@@@@@..@.@@@@@@@@....@@@@@@@@@@....@@....@@@@..@.@@@.@.@@@
@.@.@@@@.@@.@.@.@@..@.@@@@.@@.@@@@.@@@@@.@@@.@@@@@@@@@.@@@@.@@.@.@@@@.@@@@.@@@@..@@@@.@.@@.@.@.@@@@@@@.@@.@@@@@...@@@@.@@@@@@@..@@@@.@@@
.@@.@@@@@@.@.@.@@@@@@..@..@@@@....@@..@@@.@@@@@...@@@@@.@@..@@@@..@.@.@@@@.@.@...@...@@.@..@@@...@@@..@.@@@@@...@@..@@@@.@@@@@...@@.@.@@
@@@@@....@...@@..@.@...@...@@@@@@.@.@@@@.@@@@@@@.@..@@@@@@@@..@@@@...@@.@@.@.@@.@@...@@@@.@.@@@.@@..@@@@.@@@....@...@.@.@@.@.@..@..@.@@@
..@.@@.@@@@@@@@.@@.@@.@@@...@@..@@@@@@@.@..@@..@@@.@@.@@.@...@@.@@@@@.@@@@@..@@@.@.@@.@@@@.@@@.@@@..@.@@@@@@@..@@@....@@@@....@@@..@.@@@
@@@.@@@.@@...@..@.@....@@@.@@..@@.@@@.@@.@@@.@@..@..@..@.@@@.@.@@@@@@@.@@..@@.@@@.@.@@@@@.@.@@@@@@@@..@@..@.@@.@@.@.@..@@.@..@.@@@@@@@@.
@@@@@.@@@.@..@@@.@@@@@@@@@@@.@@.@@@@@.@@@@@.@@..@@@@.@..@.@@@@@@...@@@@@@.@@..@@.@@.@@.@@..@@@@.@@.@...@@@@@@...@.@@@@@.@@@@@@@@@@@@.@.@
@.@..@..@....@@@@.@.@@@@@.@@@.@@@@@.@@@@@@@@...@@.@@@.@.@..@..@..@@@@@..@@.@@..@.@@.@@.@.@.@..@@.@@.@...@.@@@@@@.@.@..@.@@.@..@@@..@@@@@
@.@@@.@@.@@@@.@...@@@.@@@.@@@@@@@@.@@@@@@@@@@.@@@....@@@@.@@@...@@@.@.@@@@.@.@@@..@..@..@@.@@@@@@.@...@@@.@@@@.@@@@@@@@@....@@@.@@.@.@@.
@@@@..@@@@@.@@@@@@.@@@@...@..@@@.@@@@@@@.@.@@@.@.@.@@@@.@...@.@.@.@@...@@@@@@@@..@@@.@@...@@.@@@.@@@.@@@@@@@@@.@@@@.@@@..@@@@.@@@.@@@.@.
.@@@@@.@@@..@@@@@.@@@@@.@..@....@@.@@.@@@.@@@@@@@.@@@....@@@@@@@@@@@.@@..@.....@.@.@@@@@@@@..@...@@@.@@@@@@@@.@@.@@.@@@@.@@@@@.@@@..@.@.
@@..@.@.@.@@@@@.@.@@@....@.@.@.@.@@@@.@@@.@..@@@@@@..@@.@@@...@@@@@...@..@@@@.@.@@..@.@@.@@@@.@@@.@@@.@...@@@.@@@.@.@@@@.@@@@@@....@.@..
@.@.@@@@.@@@.@.@@@@..@@@@@@.@..@@@..@@.@@@@..@@@@.@.@.@.@@@.@.@.@@@@@@.@.@.@...@...@@..@@@@@.@@..@@@@@@@@@.@@@@.@@@.@.@@@@@@.@@@@@...@@.
.@.@..@@@@@@@.@@@@@@.@..@..@@@@@@@@@@@@@@@.@.@....@@@@@@@.@.@@.@@..@@@@.@.@.@.@@.@@.@@@@.@.@@@.@.@@@@@@@..@..@@@@@@@@.@@@@@@@.@.@.@.@@@@
...@@@@@@..@.@@@@@@@..@@@..@@@@@@@.@@...@..@@@.@@@@@...@.@.@.@@@@@@@@@@@..@@@@.@@@@.@...@.@@.@..@@.@@.@..@@@.@@@@@@@@.@.@.@.@@@..@@.@.@.

56
04_b/lst.c Normal file
View File

@@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lst.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/15 16:17:12 by dgaillet #+# #+# */
/* Updated: 2025/12/15 16:26:55 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "aoc04_b.h"
#include <stdlib.h>
t_co *new_co(int i, int j)
{
t_co *co;
co = malloc(sizeof(t_co));
if (!co)
return (NULL);
co->i = i;
co->j = j;
co->next = NULL;
return (co);
}
void co_add_back(t_co **lst, t_co *new)
{
t_co *temp;
if (!lst)
return ;
if (!(*lst))
*lst = new;
else
{
temp = *lst;
while (temp->next)
temp = temp->next;
temp->next = new;
}
}
void clear_lst(t_co *lst)
{
t_co *temp = lst;
while (temp)
{
temp = lst->next;
free(lst);
lst = temp;
}
}

131
04_b/main.c Normal file
View File

@@ -0,0 +1,131 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 13:31:43 by dgaillet #+# #+# */
/* Updated: 2025/12/16 10:24:41 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "aoc04_b.h"
#include "get_next_char.h"
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
// 1428 ; to low
static char **parsing(void)
{
int fd = open("input", O_RDONLY);
char *temp = get_next_char(fd, '\n');
char *new;
char *str = NULL;
char **wall;
while (temp)
{
if (!str)
new = ft_strdup(temp);
else
{
new = ft_strjoin(str, temp);
free(str);
}
free(temp);
str = new;
temp = get_next_char(fd, '\n');
}
wall = ft_split(str, '\n');
return (free(str), wall);
}
static int is_roll(char **wall, int i, int j)
{
if (wall[i][j] == '@')
return (1);
return (0);
}
static int roll_arround(char **wall, int i, int j)
{
int rolls = 0;
int k = -1;
while (k <= 1)
{
if (i + k >= 0 && wall[i + k])
{
if (j > 0)
rolls += is_roll(wall, i + k, j - 1);
if (k)
rolls += is_roll(wall, i + k, j);
rolls += is_roll(wall, i + k, j + 1);
}
k++;
}
return (rolls);
}
static void delete_rolls(char **wall, t_co *lst)
{
while (lst)
{
wall[lst->i][lst->j] = '.';
lst = lst->next;
}
}
static int nb_forklift(char **wall)
{
int nb_fl = 0;
int temp;
int i = 0;
int j;
t_co *lst = NULL;
while (wall[i])
{
j = 0;
while (wall[i][j])
{
if (is_roll(wall, i, j))
{
temp = roll_arround(wall, i, j);
if (temp < 4)
{
nb_fl++;
co_add_back(&lst, new_co(i, j));
}
}
j++;
}
i++;
}
delete_rolls(wall, lst);
clear_lst(lst);
return (nb_fl);
}
int main(void)
{
char **wall = parsing();
int nb_fl = 0;
int temp = 0;
int i = 0;
temp = nb_forklift(wall);
while (temp)
{
nb_fl += temp;
temp = nb_forklift(wall);
}
while (wall[++i])
free(wall[i]);
free(wall);
printf("%d\n", nb_fl);
}

26
05/aoc05.h Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* aoc05.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/16 10:28:12 by dgaillet #+# #+# */
/* Updated: 2025/12/16 10:55:28 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#ifndef AOC05_H
# define AOC05_H
typedef struct s_range
{
long long start;
long long end;
void *next;
} t_range;
t_range *parsing(int fd);
void lst_clear(t_range *lst);
#endif

1183
05/input Normal file

File diff suppressed because it is too large Load Diff

48
05/main.c Normal file
View File

@@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/16 10:44:11 by dgaillet #+# #+# */
/* Updated: 2025/12/16 10:55:36 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "aoc05.h"
#include "get_next_char.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
static int is_fresh(t_range *lst, long long ingredient)
{
while (lst)
{
if (lst->start <= ingredient && lst->end >= ingredient)
return (1);
lst = lst->next;
}
return (0);
}
int main(void)
{
int fd = open("input", O_RDONLY);
t_range *lst = parsing(fd);
int nb_fresh = 0;
char *temp;
temp = get_next_char(fd, '\n');
while (temp)
{
nb_fresh += is_fresh(lst, atoll(temp));
free(temp);
temp = get_next_char(fd, '\n');
}
close(fd);
lst_clear(lst);
printf("%d\n", nb_fresh);
}

77
05/parsing.c Normal file
View File

@@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/16 10:30:27 by dgaillet #+# #+# */
/* Updated: 2025/12/16 10:55:01 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "aoc05.h"
#include "get_next_char.h"
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
static t_range *new_range(char *str)
{
t_range *range;
range = malloc(sizeof(t_range));
if (!range)
return (NULL);
range->start = atoll(str);
range->end = atoll(strchr(str, '-') + 1);
range->next = NULL;
return (range);
}
static void range_add_back(t_range **lst, t_range *new)
{
t_range *temp;
if (!lst)
return ;
if (!(*lst))
*lst = new;
else
{
temp = *lst;
while (temp->next)
temp = temp->next;
temp->next = new;
}
}
void lst_clear(t_range *lst)
{
t_range *temp;
while (lst)
{
temp = lst->next;
free(lst);
lst = temp;
}
}
t_range *parsing(int fd)
{
t_range *lst = NULL;
char *temp;
temp = get_next_char(fd, '\n');
while (temp && strlen(temp) > 1)
{
range_add_back(&lst, new_range(temp));
free(temp);
temp = get_next_char(fd, '\n');
}
if (temp)
free(temp);
return (lst);
}

27
05_b/aoc05.h Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* aoc05.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/16 10:28:12 by dgaillet #+# #+# */
/* Updated: 2025/12/16 11:39:24 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#ifndef AOC05_H
# define AOC05_H
typedef struct s_range
{
long long start;
long long end;
void *next;
void *pre;
} t_range;
t_range *parsing(int fd);
void lst_clear(t_range *lst);
#endif

6
05_b/example Normal file
View File

@@ -0,0 +1,6 @@
3-5
10-14
16-20
12-18
10-20
1-1000

1183
05_b/input Normal file

File diff suppressed because it is too large Load Diff

72
05_b/main.c Normal file
View File

@@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/16 10:44:11 by dgaillet #+# #+# */
/* Updated: 2025/12/16 15:25:14 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "aoc05.h"
#include "get_next_char.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
static void update_range(t_range *lst)
{
t_range *node = lst;
while (lst->pre)
lst = lst->pre;
while (lst != node)
{
if (node->start >= lst->start && node->start <= lst->end)
node->start = lst->end + 1;
if (node->end >= lst->start && node->end <= lst->end)
node->end = lst->start - 1;
if ((lst->start >= node->start && lst->start <= node->end)
&& (lst->end >= node->start && lst->end <= node->end))
{
lst->start = 0;
lst->end = -1;
}
lst = lst->next;
}
if (node->start > node->end)
{
node->start = 0;
node->end = -1;
}
}
int main(void)
{
int fd = open("input", O_RDONLY);
t_range *lst = parsing(fd);
unsigned long long nb_fresh = 0;
while (lst->next)
{
update_range(lst);
lst = lst->next;
}
update_range(lst);
while (lst->pre)
lst = lst->pre;
while (lst->next)
{
nb_fresh += 1 + lst->end - lst->start;
lst = lst->next;
}
nb_fresh += 1 + lst->end - lst->start;
while (lst->pre)
lst = lst->pre;
close(fd);
lst_clear(lst);
printf("\n%lld\n", nb_fresh);
}

79
05_b/parsing.c Normal file
View File

@@ -0,0 +1,79 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/16 10:30:27 by dgaillet #+# #+# */
/* Updated: 2025/12/16 11:51:22 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "aoc05.h"
#include "get_next_char.h"
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
static t_range *new_range(char *str)
{
t_range *range;
range = malloc(sizeof(t_range));
if (!range)
return (NULL);
range->start = atoll(str);
range->end = atoll(strchr(str, '-') + 1);
range->next = NULL;
range->pre = NULL;
return (range);
}
static void range_add_back(t_range **lst, t_range *new)
{
t_range *temp;
if (!lst)
return ;
if (!(*lst))
*lst = new;
else
{
temp = *lst;
while (temp->next)
temp = temp->next;
temp->next = new;
new->pre = temp;
}
}
void lst_clear(t_range *lst)
{
t_range *temp;
while (lst)
{
temp = lst->next;
free(lst);
lst = temp;
}
}
t_range *parsing(int fd)
{
t_range *lst = NULL;
char *temp;
temp = get_next_char(fd, '\n');
while (temp && strlen(temp) > 1)
{
range_add_back(&lst, new_range(temp));
free(temp);
temp = get_next_char(fd, '\n');
}
if (temp)
free(temp);
return (lst);
}