diff --git a/2024/10/part1.c b/2024/10/part1.c index 35424ef..2e2b5ab 100644 --- a/2024/10/part1.c +++ b/2024/10/part1.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ -/* Updated: 2024/12/10 12:31:18 by tomoron ### ########.fr */ +/* Updated: 2024/12/15 18:58:03 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,7 +59,8 @@ static char **create_map(char **split, int *height, int *width) (*height)++; while(split[0][*width]) (*width)++; - res = malloc(*height * sizeof(char *)); + res = malloc((*height + 1) * sizeof(char *)); + res[*height] = 0; *height = 0; while(split[*height]) { @@ -97,5 +98,6 @@ long int resolve_part1(char *input, char **split) } i++; } + ft_free_str_arr(locations); return(res); } diff --git a/2024/11/part1.c b/2024/11/part1.c index d93cb2f..0793a5b 100644 --- a/2024/11/part1.c +++ b/2024/11/part1.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ -/* Updated: 2024/12/11 22:19:45 by tomoron ### ########.fr */ +/* Updated: 2024/12/15 19:02:21 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -101,6 +101,7 @@ long int resolve_part1(char *input, char **split) (void)split; (void)input; t_pebble *pebble; + t_pebble *tmp; pebble = get_input(input); long int res; (void)get_input; @@ -108,8 +109,10 @@ long int resolve_part1(char *input, char **split) res = 0; while(pebble) { + tmp = pebble->next; res += get_nb(pebble->value, 0); - pebble = pebble->next; + free(pebble); + pebble = tmp; } return(res); } diff --git a/2024/11/part2.c b/2024/11/part2.c index 126c66d..fcd29e0 100644 --- a/2024/11/part2.c +++ b/2024/11/part2.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ -/* Updated: 2024/12/11 22:52:44 by tomoron ### ########.fr */ +/* Updated: 2024/12/15 19:02:10 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -112,6 +112,7 @@ long int resolve_part2(char *input, char **split) (void)split; (void)input; t_pebble *pebble; + t_pebble *tmp; long int res; long int *map; size_t map_len; @@ -124,8 +125,10 @@ long int resolve_part2(char *input, char **split) bzero(map, map_len); while(pebble) { + tmp = pebble->next; res += get_nb(pebble->value, 0, map); - pebble = pebble->next; + free(pebble); + pebble = tmp; } free(map); return(res); diff --git a/2024/12/part2.c b/2024/12/part2.c index 9c191b1..e0f7c93 100644 --- a/2024/12/part2.c +++ b/2024/12/part2.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ -/* Updated: 2024/12/13 03:02:23 by tomoron ### ########.fr */ +/* Updated: 2024/12/15 19:05:03 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -91,13 +91,19 @@ static void add_point(t_point **strt, int x, int y) static int check_surroundings(char **map, int pos[2], char c, int reset) { static t_point *counted; + t_point *tmp; int res; int x; int y; if(reset) { - counted = 0; + while(counted) + { + tmp = counted->next; + free(counted); + counted = tmp; + } return(0); } if(is_counted(counted, pos[1], pos[0])) @@ -166,6 +172,7 @@ static long int calc_price(char **map, int x, int y) perimetter = get_area_perimetter(tmp, (int [2]){y, x}, 1, locations, tmp[y][x], 0); check_surroundings(0, (int [2]){0, 0}, 0, 1); ft_free_str_arr(locations); + ft_free_str_arr(tmp); return(area * perimetter); } diff --git a/2024/14/part1.c b/2024/14/part1.c index 9b59e0c..0779939 100644 --- a/2024/14/part1.c +++ b/2024/14/part1.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ -/* Updated: 2024/12/14 12:59:57 by tomoron ### ########.fr */ +/* Updated: 2024/12/15 19:09:18 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -97,6 +97,7 @@ long int resolve_part1(char *input, char **split) { (void)input; t_robot *robot; + t_robot *tmp; long int res; robot = 0; @@ -108,5 +109,11 @@ long int resolve_part1(char *input, char **split) } update_pos(robot); res = get_result(robot); + while(robot) + { + tmp = robot->next; + free(robot); + robot = tmp; + } return(res); } diff --git a/2024/14/part2.c b/2024/14/part2.c index d620ffe..fa808ec 100644 --- a/2024/14/part2.c +++ b/2024/14/part2.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ -/* Updated: 2024/12/14 16:20:20 by tomoron ### ########.fr */ +/* Updated: 2024/12/15 19:10:24 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -146,7 +146,10 @@ static int is_easter_egg(char **map) while(map[i][j]) { if(count_area(map, (int [2]){i, j}, locations) > 50) + { + ft_free_str_arr(locations); return(1); + } j++; } i++; @@ -159,6 +162,7 @@ long int resolve_part2(char *input, char **split) { (void)input; t_robot *robot; + t_robot *tmp; long int res; char **map; @@ -177,5 +181,12 @@ long int resolve_part2(char *input, char **split) res++; fill_map(map,robot); } + while(robot) + { + tmp = robot->next; + free(robot); + robot = tmp; + } + ft_free_str_arr(map); return(res); } diff --git a/2024/15/part2.c b/2024/15/part2.c index 86ba168..174589d 100644 --- a/2024/15/part2.c +++ b/2024/15/part2.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ -/* Updated: 2024/12/15 15:06:58 by tomoron ### ########.fr */ +/* Updated: 2024/12/15 19:11:42 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -210,5 +210,6 @@ long int resolve_part2(char *input, char **split) instr++; } res = calc_score(split); + ft_free_str_arr(split); return(res); }