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:
67
06_b/main.c
Normal file
67
06_b/main.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "aoc06.h"
|
||||
#include "libft.h"
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned long long calculate_res(t_lst *lst)
|
||||
{
|
||||
unsigned long long res = 0;
|
||||
int temp[4];
|
||||
int i;
|
||||
int j;
|
||||
|
||||
if (!lst)
|
||||
return (0);
|
||||
j = 0;
|
||||
while (j < 4)
|
||||
{
|
||||
temp[j] = 0;
|
||||
i = 0;
|
||||
while (lst->nbrs[i][j])
|
||||
{
|
||||
if (ft_isdigit(lst->nbrs[i][j]))
|
||||
temp[j] = (10 * temp[j]) + (lst->nbrs[i][j] - '0');
|
||||
i++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
j = 0;
|
||||
while (j < 4)
|
||||
{
|
||||
if (temp[j])
|
||||
{
|
||||
if (lst->sign == '+')
|
||||
res += temp[j];
|
||||
if (lst->sign == '*')
|
||||
res *= temp[j];
|
||||
}
|
||||
j++;
|
||||
}
|
||||
printf("%llu\n", res);
|
||||
return (res + calculate_res(lst->next));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fd = open("input", O_RDONLY);
|
||||
t_lst *lst = parsing(fd);
|
||||
unsigned long long res = 0;
|
||||
|
||||
res = calculate_res(lst);
|
||||
lst_clear(lst);
|
||||
close (fd);
|
||||
printf("%llu\n", res);
|
||||
}
|
||||
Reference in New Issue
Block a user