/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* part2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ /* Updated: 2025/12/03 20:03:20 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #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); }