/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* part2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ /* Updated: 2025/12/06 16:16:55 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include "libft/libft.h" static char *get_ll(char **split) { char *tmp; tmp = 0; while(*(split + 1)) split++; tmp = *split; *split = 0; return(tmp); } long int resolve_part2(char *input, char **split) { (void)input; char **tmp; char *last_line; long int nb; long int res; long int cur; long int op; int i = 0; res = 0; last_line = get_ll(split); cur = 0; while(split[0][i]) { if(last_line[i] == '+') op = 1; if(last_line[i] == '*') op = 0; tmp = split; nb = 0; while(*tmp) { if(ft_isdigit((*tmp)[i])) { nb *= 10; nb += (*tmp)[i] - '0'; } tmp++; } if(nb == 0) { res += cur; cur = 0; } if(!cur) cur = nb; else { if(op) cur += nb; else cur *= nb; } i++; } res+=cur; return(res); }