/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* part2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ /* Updated: 2025/12/09 12:37:36 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include "libft/libft.h" long int get_timelines(char **map, int x, int y, long int *hash, int len) { long int res; int start_x; int start_y; start_x = x; start_y = y; if(hash[y * len + x]) return(hash[y * len + x]); while(map[y] && map[y][x] == '.') y++; if(map[y]) { res = get_timelines(map, x+1, y, hash, len); res += get_timelines(map, x-1, y, hash, len); } else res = 1; hash[start_y * len + start_x] = res; return(res); } long int *create_hashmap(char **map) { int len; int height; len = 0; height = 0; while(map[0][len]) len++; while(map[height]) height++; return(malloc(len * height * sizeof(long int))); } long int resolve_part2(char *input, char **split) { (void)input; long int res; long int *hash; int len; int s_pos; len = 0; hash = create_hashmap(split); s_pos = 0; if(!hash) return(0); while(split[0][len]) { if(split[0][len] == 'S') s_pos = len; len++; } res = get_timelines(split, s_pos, 0, hash,len); return(res); }