mirror of
https://github.com/DavidGailleton/AdventOfCode-2025.git
synced 2026-01-26 23:11:58 +00:00
06 bonus
This commit is contained in:
5
06_b/example
Normal file
5
06_b/example
Normal file
@@ -0,0 +1,5 @@
|
||||
123 328 51 64
|
||||
45 64 387 23
|
||||
6 98 215 314
|
||||
1 4 729 45
|
||||
* + * +
|
||||
10
06_b/main.c
10
06_b/main.c
@@ -6,7 +6,7 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/16 15:07:02 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/12/16 19:30:20 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/12/17 14:22:46 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// 21981441218167856 ; to high
|
||||
|
||||
unsigned long long calculate_res(t_lst *lst)
|
||||
{
|
||||
unsigned long long res = 0;
|
||||
int temp[4];
|
||||
int temp[4] = {0, 0, 0, 0};
|
||||
int i;
|
||||
int j;
|
||||
|
||||
@@ -39,6 +41,8 @@ unsigned long long calculate_res(t_lst *lst)
|
||||
j++;
|
||||
}
|
||||
j = 0;
|
||||
if (lst->sign == '*')
|
||||
res = 1;
|
||||
while (j < 4)
|
||||
{
|
||||
if (temp[j])
|
||||
@@ -51,7 +55,7 @@ unsigned long long calculate_res(t_lst *lst)
|
||||
j++;
|
||||
}
|
||||
printf("%llu\n", res);
|
||||
return (res + calculate_res(lst->next));
|
||||
return (res + calculate_res(lst->pre));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/16 16:03:38 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/12/16 20:14:05 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/12/17 14:57:13 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -88,7 +88,8 @@ static void add_nbr(char *strs[5], t_lst *lst, int i)
|
||||
if (!lst)
|
||||
return ;
|
||||
k = 0;
|
||||
while (strs[4][i + 1] != '*' && strs[4][i + 1] != '+')
|
||||
while (i >= 0 && !(strs[0][i] == ' ' && strs[1][i] == ' ' && strs[2][i] == ' '
|
||||
&& strs[3][i] == ' ' && strs[4][i] == ' '))
|
||||
{
|
||||
j = 0;
|
||||
while (j < 4)
|
||||
@@ -120,19 +121,19 @@ t_lst *parsing(int fd)
|
||||
int i = -1;
|
||||
t_lst *lst = NULL;
|
||||
|
||||
while (++i < 6)
|
||||
temp[i] = get_next_char(fd, '\n');
|
||||
int_lst = ft_split(temp[0], ' ');
|
||||
while (int_lst[i++])
|
||||
temp[++i] = get_next_char(fd, '\n');
|
||||
while (temp[i])
|
||||
temp[++i] = get_next_char(fd, '\n');
|
||||
int_lst = ft_split(temp[4], ' ');
|
||||
i = 0;
|
||||
while (int_lst[++i])
|
||||
lst_add_back(&lst, new_lst());
|
||||
clear_split(int_lst);
|
||||
int_lst = ft_split(temp[4], ' ');
|
||||
add_sign(lst, int_lst);
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
add_nbr(temp, lst, strlen(temp[0]) - 2);
|
||||
while (lst->pre)
|
||||
lst = lst->pre;
|
||||
int_lst = ft_split(temp[4], ' ');
|
||||
add_sign(lst, int_lst);
|
||||
i = -1;
|
||||
while (++i < 6)
|
||||
free(temp[i]);
|
||||
|
||||
Reference in New Issue
Block a user