mirror of
https://github.com/DavidGailleton/AdventOfCode-2025.git
synced 2026-01-26 23:11:58 +00:00
07
This commit is contained in:
142
07/input
Normal file
142
07/input
Normal file
@@ -0,0 +1,142 @@
|
||||
......................................................................S......................................................................
|
||||
.............................................................................................................................................
|
||||
......................................................................^......................................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................................^.^.....................................................................
|
||||
.............................................................................................................................................
|
||||
....................................................................^...^....................................................................
|
||||
.............................................................................................................................................
|
||||
...................................................................^.^.^.^...................................................................
|
||||
.............................................................................................................................................
|
||||
..................................................................^...^.^.^..................................................................
|
||||
.............................................................................................................................................
|
||||
.................................................................^.^.^.^.^.^.................................................................
|
||||
.............................................................................................................................................
|
||||
................................................................^.^...^.^.^.^................................................................
|
||||
.............................................................................................................................................
|
||||
...............................................................^.^.^...^...^.^...............................................................
|
||||
.............................................................................................................................................
|
||||
..............................................................^.^...^.^.^.^...^..............................................................
|
||||
.............................................................................................................................................
|
||||
.............................................................^.....^...^.^.^.^.^.............................................................
|
||||
.............................................................................................................................................
|
||||
............................................................^.^.^.^.^...^.^.^...^............................................................
|
||||
.............................................................................................................................................
|
||||
...........................................................^.....^.^.^.^...^...^.^...........................................................
|
||||
.............................................................................................................................................
|
||||
..........................................................^.^...^.......^.^.^.^.^.^..........................................................
|
||||
.............................................................................................................................................
|
||||
.........................................................^.^.^.^.^.^.^.^.^.^...^.^.^.........................................................
|
||||
.............................................................................................................................................
|
||||
........................................................^.......^.^.^.^...^.^...^.^.^........................................................
|
||||
.............................................................................................................................................
|
||||
.......................................................^.^.^.^...^.^...^...^...^...^.^.......................................................
|
||||
.............................................................................................................................................
|
||||
......................................................^.^...^.^.^.^...^.....^.^.^.^.^.^......................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.....................................................
|
||||
.............................................................................................................................................
|
||||
....................................................^.^.^...^.^.^.^...^.^...^.^...^...^.^....................................................
|
||||
.............................................................................................................................................
|
||||
...................................................^.^.^.^.^.......^.^.^.^.^.^...^.^...^.^...................................................
|
||||
.............................................................................................................................................
|
||||
..................................................^.......^...^.^.^...^.....^.^.........^.^..................................................
|
||||
.............................................................................................................................................
|
||||
.................................................^.^.^.^.^.^.^.^.^.^.^...^...^...^.^.....^.^.................................................
|
||||
.............................................................................................................................................
|
||||
................................................^...^.^...^.^.^.......^.....^...^...^.....^.^................................................
|
||||
.............................................................................................................................................
|
||||
...............................................^.^.^...^.^...^...^.....^...^.^.^.^.^...^.^.^.^...............................................
|
||||
.............................................................................................................................................
|
||||
..............................................^.......^.^.^.^...^.^.....^...^.^.^.^.^.^.^.^.^.^..............................................
|
||||
.............................................................................................................................................
|
||||
.............................................^.^...^.^.^...^.^.^.^.^...^.^.^.^.........^.^.^.^.^.............................................
|
||||
.............................................................................................................................................
|
||||
............................................^.^.^.^.....^...^.....^.^.^.^...^.^.^.^...^...^.^.^.^............................................
|
||||
.............................................................................................................................................
|
||||
...........................................^.....^.^.^.......^.....^.^...^.^.^.^.^.^.^.^...^.^.^.^...........................................
|
||||
.............................................................................................................................................
|
||||
..........................................^.^.^.^.^.^...^.^.^.....^.^.....^...^.^.^.^.....^.^.^...^..........................................
|
||||
.............................................................................................................................................
|
||||
.........................................^.^.^.^...............^.^.^...^.^.........^.^.^...^.^...^.^.........................................
|
||||
.............................................................................................................................................
|
||||
........................................^.^.^.^.^.^.^...^.^.^...^...^.^.^.^.^.^.^.^...^.^.....^.^.^.^........................................
|
||||
.............................................................................................................................................
|
||||
.......................................^...^.^.^.^.^.^.^.^...^...^.^.^.......^.^.^.^.^.^.........^...^.......................................
|
||||
.............................................................................................................................................
|
||||
......................................^.^.^.^.^.^...^.^.^.......^.....^...^.^.......^.^...^.^.^...^...^......................................
|
||||
.............................................................................................................................................
|
||||
.....................................^.^.^.^.^.....^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.....................................
|
||||
.............................................................................................................................................
|
||||
....................................^...^.^.^.^.^...^.^.^.^.........^.^.^.^.^.^.^...^.^.^.^...^.^...^...^....................................
|
||||
.............................................................................................................................................
|
||||
...................................^.^.^...^.^.^.^.^.^.......^.^.^.^.^...^.^.^.^.^.^.^.^...^.^...^.....^.^...................................
|
||||
.............................................................................................................................................
|
||||
..................................^.^...^.......^.^.^.^...^...^.^.....^.......^.^.^...^...^.^.^.^.^.^.^.^.^..................................
|
||||
.............................................................................................................................................
|
||||
.................................^.^.....^...^.^.^...^...^.^.^.......^.^.^.^.^.^.^.^.^...^.....^.^.^.^.^.^.^.................................
|
||||
.............................................................................................................................................
|
||||
................................^.....^.^.^...^.^...^...^...^.^.^.^...^.^.^.^...^.^...^.^.^.^...^.^.^...^...^................................
|
||||
.............................................................................................................................................
|
||||
...............................^.^.^.^.^.......^...^.^...^...^.^.^.^.^.^...^.^.^.....^.^.^.^.^.......^.....^.^...............................
|
||||
.............................................................................................................................................
|
||||
..............................^...^...^.....^.^...^.^.^.^...^.^.^...^.^...^.^.^.^.^.^...^...^.^.^.........^.^.^..............................
|
||||
.............................................................................................................................................
|
||||
.............................^.^.....^.....^...^.^.^.^...^.....^...^.^.^...^...^.^...^.^...^.^.^.^.^.^.^...^...^.............................
|
||||
.............................................................................................................................................
|
||||
............................^.^.^...^.^...^.^.^...^.^.^...^.^.^.^.....^...^.^.^.^.....^.^.^...^.^.^.^.^.^.^.^...^............................
|
||||
.............................................................................................................................................
|
||||
...........................^.^.^.......^.^.^.^.^...^.^.^.^.^...^.....^.^.^.^.^.^...^...^.^.^.^.^.^.^...^.^.^...^.^...........................
|
||||
.............................................................................................................................................
|
||||
..........................^.^.....^...^.^.^...^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^...^.^.^...^...^.^...^.^.^...^.^.^..........................
|
||||
.............................................................................................................................................
|
||||
.........................^.^...^.^.^...^.^.^.^.^...^.^...^.............^.^.^.^.......^.^.^.^.^...^.^.^...^.^.^.^.^.^.........................
|
||||
.............................................................................................................................................
|
||||
........................^.^.........^.^.^.^.^.^...^.......^...^.^.^...^.^.^.....^.^.^.......^.....^.^.^.^.^.^.^.^.^.^........................
|
||||
.............................................................................................................................................
|
||||
.......................^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.....^.^...^.^.^.^...^.^.^.^.......................
|
||||
.............................................................................................................................................
|
||||
......................^.^.^.^.......^.^.^...^.^...^.^...^...^.^...^...^.....^.^...^.^.^.^.^.^.^...^.^.^.^...^.^.^.^.^.^......................
|
||||
.............................................................................................................................................
|
||||
.....................^.^.^.^...^...^...^.^.^.....^.^.^.^...^...^.^.^.^.^.........^.^.^...^.^.^.^.....^.^.^...^.^...^.^.^.....................
|
||||
.............................................................................................................................................
|
||||
....................^.^.^...^...^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.....^...^.^.^.^.......^...^.^.^.^.^.^...^.^.^...^.^...^....................
|
||||
.............................................................................................................................................
|
||||
...................^.^...^.^.^.^.^...^.^.^.^...^.^.^.^.^.^...^.^...^...^.^.^.^.......^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^...................
|
||||
.............................................................................................................................................
|
||||
..................^.^.^.^...^.....^.^...^...^.....^.....^.^...^...^...^.^.......^.........^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^..................
|
||||
.............................................................................................................................................
|
||||
.................^.^.^.^.^.^.^...^.^.^...^...^.^.^.^.^.^.^.^.^.....^.^...^.....^.^...^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.................
|
||||
.............................................................................................................................................
|
||||
................^.......^.^.^.^...^.^...^.^.^.^.^.^.^.......^.^.^.^.^.....^.^.^.^.^.^.....^.^.^...^...^.^.^...^.^.....^.^.^.^................
|
||||
.............................................................................................................................................
|
||||
...............^.^.^.^.^.^.......^.^.^.......^.^.^...^.^.....^.^.........^.........^.^...^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.^.^...............
|
||||
.............................................................................................................................................
|
||||
..............^.^.^.^.^.....^.^.^.^.^.....^.^.^.^.^.^.^...^.^...^...^.^.^...^.^.^...^...^...^.^.^.^.^.^.^.........^.^.^.^.^.^.^..............
|
||||
.............................................................................................................................................
|
||||
.............^.^.^.^.^.....^.^...^.^.^.....^.^.....^...^.^.....^.^.^...^.^.^.^...^...^.....^.^.^...^...^.^.....^.....^.....^...^.............
|
||||
.............................................................................................................................................
|
||||
............^.^.....^.^.^.^.^.^.^.^.^.....^...^.^.....^.^.^.^.^...^...^.^.^.^.^.^.^...^...^.....^.........^.....^.^.^.^.^.^...^.^............
|
||||
.............................................................................................................................................
|
||||
...........^.^...^.^.^.^...^.......^...^.^.^.^.....^.^.^.^.^.....^.^.^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.......^.^...^...........
|
||||
.............................................................................................................................................
|
||||
..........^...^.^.^.^.........^.^.^.^.^...^.^.^.^...^.^.^.^.^.^.....^...^...^...^.^.^.^...^...^...^...^...^.......^...^...^.^...^.^..........
|
||||
.............................................................................................................................................
|
||||
.........^...^.^.^...^.^.^.^...^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^...^.^...^.....^.^.....^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.....^.^.........
|
||||
.............................................................................................................................................
|
||||
........^.^...^.......^...^...^...^...^.........^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^...^.^...^.^...^.^.....^........
|
||||
.............................................................................................................................................
|
||||
.......^...^.^.....^.^.^.^.^.^.^...^...^.^.^.^.....^.^.^...^.^.^...^.^...^...^.^.^.^.^.^.^.^...^.^.^.^.^.....^.^.^.^...^.^.^.^.^.^.^.^.......
|
||||
.............................................................................................................................................
|
||||
......^.^.^.........^.^.^...^...^.^...^.^.^.^...^.^...^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^.^......
|
||||
.............................................................................................................................................
|
||||
.....^.^.....^.^...^.^.^...^...^.^.^.........^.^.^...^.^...^.^.^.^.^.^.^...^...^.^.^.^...^.^...^.^.^.^.^.^.^.^.^...^.^...^.^...^.^.....^.....
|
||||
.............................................................................................................................................
|
||||
....^.^.^.....^...^.^.^.^.....^.....^...^.......^.^...^...^...^.^.^.^.^.....^.^.....^.^...^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^...^....
|
||||
.............................................................................................................................................
|
||||
...^.^...^.^...^.^.^.^...^.^.......^.^.^.^.^...^...^.^...^...^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^.^...^...
|
||||
.............................................................................................................................................
|
||||
..^.^.^.^.^.....^...^.^.^.^...^.^...^...^.^.^.^...^...^...^.^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^...^...^...^..
|
||||
.............................................................................................................................................
|
||||
.^.^...^.^.^...^.....^.^.^...^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^...^...^.^.^.....^.^...^...^.^.^.^.^.^.^.^.
|
||||
.............................................................................................................................................
|
||||
64
07/main.c
Normal file
64
07/main.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/17 14:58:08 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/12/17 15:25:49 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char **parsing(int fd);
|
||||
|
||||
static size_t nb_split(char **tab)
|
||||
{
|
||||
size_t nb_split = 0;
|
||||
int i = 0;
|
||||
int j;
|
||||
|
||||
while (tab[i])
|
||||
{
|
||||
j = 0;
|
||||
while (tab[i][j])
|
||||
{
|
||||
if ((tab[i][j] == 'S' || tab[i][j] == '|' ) && tab[i + 1] && tab[i+1][j] != '^')
|
||||
tab[i + 1][j] = '|';
|
||||
else if (tab[i][j] == '^' && tab[i - 1][j] == '|')
|
||||
{
|
||||
tab[i][j + 1] = '|';
|
||||
tab[i][j - 1] = '|';
|
||||
if (tab[i + 1] && tab[i + 1][j + 1] != '^')
|
||||
tab[i + 1][j + 1] = '|';
|
||||
if (tab[i + 1] && tab[i + 1][j - 1] != '^')
|
||||
tab[i + 1][j - 1] = '|';
|
||||
nb_split++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (nb_split);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fd = open("input", O_RDONLY);
|
||||
char **tab = parsing(fd);
|
||||
int i = 0;
|
||||
|
||||
printf("%zu\n", nb_split(tab));
|
||||
while (tab[i])
|
||||
{
|
||||
free(tab[i]);
|
||||
i++;
|
||||
}
|
||||
free(tab);
|
||||
close(fd);
|
||||
}
|
||||
60
07/parsing.c
Normal file
60
07/parsing.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/17 15:02:13 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/12/17 15:29:54 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "get_next_char.h"
|
||||
|
||||
size_t tab_len(char **tab)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
if (!tab)
|
||||
return (0);
|
||||
while (tab[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char **tab_extend(char **tab, char *str)
|
||||
{
|
||||
char **new_tab;
|
||||
size_t i = 0;
|
||||
size_t len = tab_len(tab);
|
||||
|
||||
new_tab = malloc(sizeof(char *) * (len + 2));
|
||||
if (!new_tab)
|
||||
return (NULL);
|
||||
while (i < len)
|
||||
{
|
||||
new_tab[i] = tab[i];
|
||||
i++;
|
||||
}
|
||||
new_tab[len] = str;
|
||||
new_tab[len + 1] = NULL;
|
||||
if (len > 0)
|
||||
free(tab);
|
||||
return (new_tab);
|
||||
}
|
||||
|
||||
char **parsing(int fd)
|
||||
{
|
||||
char **tab = NULL;
|
||||
char *temp;
|
||||
|
||||
temp = get_next_char(fd, '\n');
|
||||
while (temp)
|
||||
{
|
||||
tab = tab_extend(tab, temp);
|
||||
temp = get_next_char(fd, '\n');
|
||||
}
|
||||
return (tab);
|
||||
}
|
||||
Reference in New Issue
Block a user