add day 03

This commit is contained in:
2025-12-03 20:03:55 +01:00
parent 786310898d
commit 09472f2e96
5 changed files with 262 additions and 0 deletions

69
2025/3/part2.c Normal file
View File

@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* part2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
/* Updated: 2025/12/03 20:03:20 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include "libft/libft.h"
long int get_max_pos(char *line, int n)
{
int i;
int found;
int found_i;
found = '0';
i = 0;
found_i = 0;
while(line[i] && i < n)
{
if(line[i] > found)
{
found = line[i];
found_i = i;
}
i++;
}
return(found_i);
}
static long int get_max_jolt(char *line, long int cur_nb, int rec_i)
{
int end;
int len;
int ind;
if(rec_i == 0)
return(cur_nb);
len = ft_strlen(line);
end = len - (rec_i -1);
ind = get_max_pos(line, end);
cur_nb = cur_nb * 10 + (line[ind] - '0');
return(get_max_jolt(line + ind + 1, cur_nb, rec_i - 1));
}
long int resolve_part2(char *input, char **split)
{
(void)input;
long int res;
long int tmp;
res = 0;
while(*split)
{
tmp = get_max_jolt(*split, 0, 12);
res+=tmp;
split++;
}
return(res);
}