From 3b878c0bd0b26508943831050cb8a9e0b5624824 Mon Sep 17 00:00:00 2001 From: David Gailleton Date: Wed, 17 Dec 2025 15:30:28 +0100 Subject: [PATCH] 07 --- 07/input | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++ 07/main.c | 64 +++++++++++++++++++++++ 07/parsing.c | 60 ++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 07/input create mode 100644 07/main.c create mode 100644 07/parsing.c diff --git a/07/input b/07/input new file mode 100644 index 0000000..a33dba5 --- /dev/null +++ b/07/input @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^...^.................................................................... +............................................................................................................................................. +...................................................................^.^.^.^................................................................... +............................................................................................................................................. +..................................................................^...^.^.^.................................................................. +............................................................................................................................................. +.................................................................^.^.^.^.^.^................................................................. +............................................................................................................................................. +................................................................^.^...^.^.^.^................................................................ +............................................................................................................................................. +...............................................................^.^.^...^...^.^............................................................... +............................................................................................................................................. +..............................................................^.^...^.^.^.^...^.............................................................. +............................................................................................................................................. +.............................................................^.....^...^.^.^.^.^............................................................. +............................................................................................................................................. +............................................................^.^.^.^.^...^.^.^...^............................................................ +............................................................................................................................................. +...........................................................^.....^.^.^.^...^...^.^........................................................... +............................................................................................................................................. +..........................................................^.^...^.......^.^.^.^.^.^.......................................................... +............................................................................................................................................. +.........................................................^.^.^.^.^.^.^.^.^.^...^.^.^......................................................... +............................................................................................................................................. +........................................................^.......^.^.^.^...^.^...^.^.^........................................................ +............................................................................................................................................. +.......................................................^.^.^.^...^.^...^...^...^...^.^....................................................... +............................................................................................................................................. +......................................................^.^...^.^.^.^...^.....^.^.^.^.^.^...................................................... +............................................................................................................................................. +.....................................................^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^..................................................... +............................................................................................................................................. +....................................................^.^.^...^.^.^.^...^.^...^.^...^...^.^.................................................... +............................................................................................................................................. +...................................................^.^.^.^.^.......^.^.^.^.^.^...^.^...^.^................................................... +............................................................................................................................................. +..................................................^.......^...^.^.^...^.....^.^.........^.^.................................................. +............................................................................................................................................. +.................................................^.^.^.^.^.^.^.^.^.^.^...^...^...^.^.....^.^................................................. +............................................................................................................................................. +................................................^...^.^...^.^.^.......^.....^...^...^.....^.^................................................ +............................................................................................................................................. +...............................................^.^.^...^.^...^...^.....^...^.^.^.^.^...^.^.^.^............................................... +............................................................................................................................................. +..............................................^.......^.^.^.^...^.^.....^...^.^.^.^.^.^.^.^.^.^.............................................. +............................................................................................................................................. +.............................................^.^...^.^.^...^.^.^.^.^...^.^.^.^.........^.^.^.^.^............................................. +............................................................................................................................................. +............................................^.^.^.^.....^...^.....^.^.^.^...^.^.^.^...^...^.^.^.^............................................ +............................................................................................................................................. +...........................................^.....^.^.^.......^.....^.^...^.^.^.^.^.^.^.^...^.^.^.^........................................... +............................................................................................................................................. +..........................................^.^.^.^.^.^...^.^.^.....^.^.....^...^.^.^.^.....^.^.^...^.......................................... +............................................................................................................................................. +.........................................^.^.^.^...............^.^.^...^.^.........^.^.^...^.^...^.^......................................... +............................................................................................................................................. +........................................^.^.^.^.^.^.^...^.^.^...^...^.^.^.^.^.^.^.^...^.^.....^.^.^.^........................................ +............................................................................................................................................. +.......................................^...^.^.^.^.^.^.^.^...^...^.^.^.......^.^.^.^.^.^.........^...^....................................... +............................................................................................................................................. +......................................^.^.^.^.^.^...^.^.^.......^.....^...^.^.......^.^...^.^.^...^...^...................................... +............................................................................................................................................. +.....................................^.^.^.^.^.....^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^..................................... +............................................................................................................................................. +....................................^...^.^.^.^.^...^.^.^.^.........^.^.^.^.^.^.^...^.^.^.^...^.^...^...^.................................... +............................................................................................................................................. +...................................^.^.^...^.^.^.^.^.^.......^.^.^.^.^...^.^.^.^.^.^.^.^...^.^...^.....^.^................................... +............................................................................................................................................. +..................................^.^...^.......^.^.^.^...^...^.^.....^.......^.^.^...^...^.^.^.^.^.^.^.^.^.................................. +............................................................................................................................................. +.................................^.^.....^...^.^.^...^...^.^.^.......^.^.^.^.^.^.^.^.^...^.....^.^.^.^.^.^.^................................. +............................................................................................................................................. +................................^.....^.^.^...^.^...^...^...^.^.^.^...^.^.^.^...^.^...^.^.^.^...^.^.^...^...^................................ +............................................................................................................................................. +...............................^.^.^.^.^.......^...^.^...^...^.^.^.^.^.^...^.^.^.....^.^.^.^.^.......^.....^.^............................... +............................................................................................................................................. +..............................^...^...^.....^.^...^.^.^.^...^.^.^...^.^...^.^.^.^.^.^...^...^.^.^.........^.^.^.............................. +............................................................................................................................................. +.............................^.^.....^.....^...^.^.^.^...^.....^...^.^.^...^...^.^...^.^...^.^.^.^.^.^.^...^...^............................. +............................................................................................................................................. +............................^.^.^...^.^...^.^.^...^.^.^...^.^.^.^.....^...^.^.^.^.....^.^.^...^.^.^.^.^.^.^.^...^............................ +............................................................................................................................................. +...........................^.^.^.......^.^.^.^.^...^.^.^.^.^...^.....^.^.^.^.^.^...^...^.^.^.^.^.^.^...^.^.^...^.^........................... +............................................................................................................................................. +..........................^.^.....^...^.^.^...^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^...^.^.^...^...^.^...^.^.^...^.^.^.......................... +............................................................................................................................................. +.........................^.^...^.^.^...^.^.^.^.^...^.^...^.............^.^.^.^.......^.^.^.^.^...^.^.^...^.^.^.^.^.^......................... +............................................................................................................................................. +........................^.^.........^.^.^.^.^.^...^.......^...^.^.^...^.^.^.....^.^.^.......^.....^.^.^.^.^.^.^.^.^.^........................ +............................................................................................................................................. +.......................^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.....^.^...^.^.^.^...^.^.^.^....................... +............................................................................................................................................. +......................^.^.^.^.......^.^.^...^.^...^.^...^...^.^...^...^.....^.^...^.^.^.^.^.^.^...^.^.^.^...^.^.^.^.^.^...................... +............................................................................................................................................. +.....................^.^.^.^...^...^...^.^.^.....^.^.^.^...^...^.^.^.^.^.........^.^.^...^.^.^.^.....^.^.^...^.^...^.^.^..................... +............................................................................................................................................. +....................^.^.^...^...^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.....^...^.^.^.^.......^...^.^.^.^.^.^...^.^.^...^.^...^.................... +............................................................................................................................................. +...................^.^...^.^.^.^.^...^.^.^.^...^.^.^.^.^.^...^.^...^...^.^.^.^.......^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^................... +............................................................................................................................................. +..................^.^.^.^...^.....^.^...^...^.....^.....^.^...^...^...^.^.......^.........^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.................. +............................................................................................................................................. +.................^.^.^.^.^.^.^...^.^.^...^...^.^.^.^.^.^.^.^.^.....^.^...^.....^.^...^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^................. +............................................................................................................................................. +................^.......^.^.^.^...^.^...^.^.^.^.^.^.^.......^.^.^.^.^.....^.^.^.^.^.^.....^.^.^...^...^.^.^...^.^.....^.^.^.^................ +............................................................................................................................................. +...............^.^.^.^.^.^.......^.^.^.......^.^.^...^.^.....^.^.........^.........^.^...^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.^.^............... +............................................................................................................................................. +..............^.^.^.^.^.....^.^.^.^.^.....^.^.^.^.^.^.^...^.^...^...^.^.^...^.^.^...^...^...^.^.^.^.^.^.^.........^.^.^.^.^.^.^.............. +............................................................................................................................................. +.............^.^.^.^.^.....^.^...^.^.^.....^.^.....^...^.^.....^.^.^...^.^.^.^...^...^.....^.^.^...^...^.^.....^.....^.....^...^............. +............................................................................................................................................. +............^.^.....^.^.^.^.^.^.^.^.^.....^...^.^.....^.^.^.^.^...^...^.^.^.^.^.^.^...^...^.....^.........^.....^.^.^.^.^.^...^.^............ +............................................................................................................................................. +...........^.^...^.^.^.^...^.......^...^.^.^.^.....^.^.^.^.^.....^.^.^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.......^.^...^........... +............................................................................................................................................. +..........^...^.^.^.^.........^.^.^.^.^...^.^.^.^...^.^.^.^.^.^.....^...^...^...^.^.^.^...^...^...^...^...^.......^...^...^.^...^.^.......... +............................................................................................................................................. +.........^...^.^.^...^.^.^.^...^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^...^.^...^.....^.^.....^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.....^.^......... +............................................................................................................................................. +........^.^...^.......^...^...^...^...^.........^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^...^.^...^.^...^.^.....^........ +............................................................................................................................................. +.......^...^.^.....^.^.^.^.^.^.^...^...^.^.^.^.....^.^.^...^.^.^...^.^...^...^.^.^.^.^.^.^.^...^.^.^.^.^.....^.^.^.^...^.^.^.^.^.^.^.^....... +............................................................................................................................................. +......^.^.^.........^.^.^...^...^.^...^.^.^.^...^.^...^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^.^...... +............................................................................................................................................. +.....^.^.....^.^...^.^.^...^...^.^.^.........^.^.^...^.^...^.^.^.^.^.^.^...^...^.^.^.^...^.^...^.^.^.^.^.^.^.^.^...^.^...^.^...^.^.....^..... +............................................................................................................................................. +....^.^.^.....^...^.^.^.^.....^.....^...^.......^.^...^...^...^.^.^.^.^.....^.^.....^.^...^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^...^.... +............................................................................................................................................. +...^.^...^.^...^.^.^.^...^.^.......^.^.^.^.^...^...^.^...^...^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^.^...^... +............................................................................................................................................. +..^.^.^.^.^.....^...^.^.^.^...^.^...^...^.^.^.^...^...^...^.^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^...^...^...^.. +............................................................................................................................................. +.^.^...^.^.^...^.....^.^.^...^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^...^...^.^.^.....^.^...^...^.^.^.^.^.^.^.^. +............................................................................................................................................. diff --git a/07/main.c b/07/main.c new file mode 100644 index 0000000..3d26ef4 --- /dev/null +++ b/07/main.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dgaillet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/12/17 14:58:08 by dgaillet #+# #+# */ +/* Updated: 2025/12/17 15:25:49 by dgaillet ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +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); +} diff --git a/07/parsing.c b/07/parsing.c new file mode 100644 index 0000000..f53e5dd --- /dev/null +++ b/07/parsing.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parsing.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dgaillet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/12/17 15:02:13 by dgaillet #+# #+# */ +/* Updated: 2025/12/17 15:29:54 by dgaillet ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#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); +}