free everything in day 10-15
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/17 23:03:36 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)++;
|
(*height)++;
|
||||||
while(split[0][*width])
|
while(split[0][*width])
|
||||||
(*width)++;
|
(*width)++;
|
||||||
res = malloc(*height * sizeof(char *));
|
res = malloc((*height + 1) * sizeof(char *));
|
||||||
|
res[*height] = 0;
|
||||||
*height = 0;
|
*height = 0;
|
||||||
while(split[*height])
|
while(split[*height])
|
||||||
{
|
{
|
||||||
@ -97,5 +98,6 @@ long int resolve_part1(char *input, char **split)
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
ft_free_str_arr(locations);
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/17 23:03:36 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)split;
|
||||||
(void)input;
|
(void)input;
|
||||||
t_pebble *pebble;
|
t_pebble *pebble;
|
||||||
|
t_pebble *tmp;
|
||||||
pebble = get_input(input);
|
pebble = get_input(input);
|
||||||
long int res;
|
long int res;
|
||||||
(void)get_input;
|
(void)get_input;
|
||||||
@ -108,8 +109,10 @@ long int resolve_part1(char *input, char **split)
|
|||||||
res = 0;
|
res = 0;
|
||||||
while(pebble)
|
while(pebble)
|
||||||
{
|
{
|
||||||
|
tmp = pebble->next;
|
||||||
res += get_nb(pebble->value, 0);
|
res += get_nb(pebble->value, 0);
|
||||||
pebble = pebble->next;
|
free(pebble);
|
||||||
|
pebble = tmp;
|
||||||
}
|
}
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/17 23:03:36 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)split;
|
||||||
(void)input;
|
(void)input;
|
||||||
t_pebble *pebble;
|
t_pebble *pebble;
|
||||||
|
t_pebble *tmp;
|
||||||
long int res;
|
long int res;
|
||||||
long int *map;
|
long int *map;
|
||||||
size_t map_len;
|
size_t map_len;
|
||||||
@ -124,8 +125,10 @@ long int resolve_part2(char *input, char **split)
|
|||||||
bzero(map, map_len);
|
bzero(map, map_len);
|
||||||
while(pebble)
|
while(pebble)
|
||||||
{
|
{
|
||||||
|
tmp = pebble->next;
|
||||||
res += get_nb(pebble->value, 0, map);
|
res += get_nb(pebble->value, 0, map);
|
||||||
pebble = pebble->next;
|
free(pebble);
|
||||||
|
pebble = tmp;
|
||||||
}
|
}
|
||||||
free(map);
|
free(map);
|
||||||
return(res);
|
return(res);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/17 23:03:36 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 int check_surroundings(char **map, int pos[2], char c, int reset)
|
||||||
{
|
{
|
||||||
static t_point *counted;
|
static t_point *counted;
|
||||||
|
t_point *tmp;
|
||||||
int res;
|
int res;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
if(reset)
|
if(reset)
|
||||||
{
|
{
|
||||||
counted = 0;
|
while(counted)
|
||||||
|
{
|
||||||
|
tmp = counted->next;
|
||||||
|
free(counted);
|
||||||
|
counted = tmp;
|
||||||
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
if(is_counted(counted, pos[1], pos[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);
|
perimetter = get_area_perimetter(tmp, (int [2]){y, x}, 1, locations, tmp[y][x], 0);
|
||||||
check_surroundings(0, (int [2]){0, 0}, 0, 1);
|
check_surroundings(0, (int [2]){0, 0}, 0, 1);
|
||||||
ft_free_str_arr(locations);
|
ft_free_str_arr(locations);
|
||||||
|
ft_free_str_arr(tmp);
|
||||||
return(area * perimetter);
|
return(area * perimetter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/17 23:03:36 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;
|
(void)input;
|
||||||
t_robot *robot;
|
t_robot *robot;
|
||||||
|
t_robot *tmp;
|
||||||
long int res;
|
long int res;
|
||||||
|
|
||||||
robot = 0;
|
robot = 0;
|
||||||
@ -108,5 +109,11 @@ long int resolve_part1(char *input, char **split)
|
|||||||
}
|
}
|
||||||
update_pos(robot);
|
update_pos(robot);
|
||||||
res = get_result(robot);
|
res = get_result(robot);
|
||||||
|
while(robot)
|
||||||
|
{
|
||||||
|
tmp = robot->next;
|
||||||
|
free(robot);
|
||||||
|
robot = tmp;
|
||||||
|
}
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/17 23:03:36 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])
|
while(map[i][j])
|
||||||
{
|
{
|
||||||
if(count_area(map, (int [2]){i, j}, locations) > 50)
|
if(count_area(map, (int [2]){i, j}, locations) > 50)
|
||||||
|
{
|
||||||
|
ft_free_str_arr(locations);
|
||||||
return(1);
|
return(1);
|
||||||
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
@ -159,6 +162,7 @@ long int resolve_part2(char *input, char **split)
|
|||||||
{
|
{
|
||||||
(void)input;
|
(void)input;
|
||||||
t_robot *robot;
|
t_robot *robot;
|
||||||
|
t_robot *tmp;
|
||||||
long int res;
|
long int res;
|
||||||
char **map;
|
char **map;
|
||||||
|
|
||||||
@ -177,5 +181,12 @@ long int resolve_part2(char *input, char **split)
|
|||||||
res++;
|
res++;
|
||||||
fill_map(map,robot);
|
fill_map(map,robot);
|
||||||
}
|
}
|
||||||
|
while(robot)
|
||||||
|
{
|
||||||
|
tmp = robot->next;
|
||||||
|
free(robot);
|
||||||
|
robot = tmp;
|
||||||
|
}
|
||||||
|
ft_free_str_arr(map);
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/17 23:03:36 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++;
|
instr++;
|
||||||
}
|
}
|
||||||
res = calc_score(split);
|
res = calc_score(split);
|
||||||
|
ft_free_str_arr(split);
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user