Compare commits

...

3 Commits

Author SHA1 Message Date
3dc5e7f8d9 add day 9 (a bit slow) 2025-12-10 15:08:47 +01:00
fcbd8c4d33 add day 8 2025-12-09 19:50:09 +01:00
0aaee9ff22 add day 7 2025-12-09 12:38:42 +01:00
16 changed files with 1242 additions and 0 deletions

69
2025/7/Makefile Normal file
View File

@ -0,0 +1,69 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/07/17 15:48:36 by tomoron #+# #+# #
# Updated: 2025/12/02 14:14:04 by tomoron ### ########.fr #
# #
# **************************************************************************** #
SRCS = main.c\
part1.c\
part2.c
OBJS = $(SRCS:.c=.o)
FLAGS = -Wextra -Werror -Wall -g
LIB = libft/libft.a
all: $(LIB) a.out test
cp test cur_input
./a.out
f: $(LIB) a.out input
cp input cur_input
./a.out
test:
touch test
input:
touch input
cp:
cp part1.c part2.c
sed -i 's/resolve_part1/resolve_part2/g' part2.c
$(LIB): libft
make -C libft
libft:
cp -r ../../libft .
main.c:
cp ../../main.c .
part1.c:
cp ../../part1.c .
part2.c:
cp ../../part2.c .
a.out: main.c $(OBJS) $(LIB)
clang $(FLAGS) $(OBJS) $(LIB)
clean:
rm -rf $(OBJS)
rm -rf libft
fclean: clean
rm -rf a.out
.c.o:
clang $(FLAGS) -c $< -o $@
.PHONY: t all clean fclean cp

67
2025/7/main.c Normal file
View File

@ -0,0 +1,67 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "libft/libft.h"
long int resolve_part1(char *input, char **split);
long int resolve_part2(char *input, char **split);
char *get_input(char *file)
{
int fd;
int rd_len;
char buffer[1000];
int len;
char *res;
fd = open(file, O_RDONLY);
len = 0;
if(fd < 0)
return(0);
rd_len = -1;
while(rd_len)
{
rd_len = read(fd, buffer, 1000);
len+= rd_len;
}
close(fd);
res = malloc(len + 1);
if(!res)
return(0);
fd = open(file, O_RDONLY);
if(fd < 0)
return(0);
rd_len = read(fd,res, len);
res[len] = 0;
close(fd);
return(res);
}
int main(void)
{
char *input;
char *input_cpy;
char **split;
input = get_input("cur_input");
input_cpy = ft_strdup(input);
if(!input || !input_cpy)
{
fprintf(stderr, "file read error\n");
return(1);
}
split = ft_split(input, '\n');
if(!split)
return(1);
printf("result part 1: %ld\n", resolve_part1(input, split));
ft_free_str_arr(split);
split = ft_split(input_cpy, '\n');
if(!split)
return(1);
printf("result part 2: %ld\n", resolve_part2(input, split));
ft_free_str_arr(split);
free(input);
free(input_cpy);
return(0);
}

51
2025/7/part1.c Normal file
View File

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* part1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
/* Updated: 2025/12/09 12:30:27 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include "libft/libft.h"
long int resolve_part1(char *input, char **split)
{
(void)input;
int x = 0;
int y = 0;
long int res;
int map_height = 0;
res = 0;
while(split[map_height])
map_height++;
while(y < map_height - 1)
{
x = 0;
while(split[y][x])
{
if(split[y][x] == 'S')
{
if(split[y+1][x] == '^')
{
split[y + 1][x - 1] = 'S';
split[y + 1][x + 1] = 'S';
res++;
}
else
split[y + 1][x] = 'S';
}
x++;
}
y++;
}
return(res);
}

77
2025/7/part2.c Normal file
View File

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* part2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
/* Updated: 2025/12/09 12:37:36 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#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);
}

16
2025/7/test Normal file
View File

@ -0,0 +1,16 @@
.......S.......
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............

69
2025/8/Makefile Normal file
View File

@ -0,0 +1,69 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/07/17 15:48:36 by tomoron #+# #+# #
# Updated: 2025/12/09 16:21:44 by tomoron ### ########.fr #
# #
# **************************************************************************** #
SRCS = main.c\
part1.c\
part2.c
OBJS = $(SRCS:.c=.o)
FLAGS = -Wextra -Werror -Wall -g
LIB = libft/libft.a
all: $(LIB) a.out test
cp test cur_input
./a.out
f: $(LIB) a.out input
cp input cur_input
./a.out
test:
touch test
input:
touch input
cp:
cp part1.c part2.c
sed -i 's/resolve_part1/resolve_part2/g' part2.c
$(LIB): libft
make -C libft
libft:
cp -r ../../libft .
main.c:
cp ../../main.c .
part1.c:
cp ../../part1.c .
part2.c:
cp ../../part2.c .
a.out: main.c $(OBJS) $(LIB)
clang $(FLAGS) $(OBJS) $(LIB) -lm
clean:
rm -rf $(OBJS)
rm -rf libft
fclean: clean
rm -rf a.out
.c.o:
clang $(FLAGS) -c $< -o $@
.PHONY: t all clean fclean cp

67
2025/8/main.c Normal file
View File

@ -0,0 +1,67 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "libft/libft.h"
long int resolve_part1(char *input, char **split);
long int resolve_part2(char *input, char **split);
char *get_input(char *file)
{
int fd;
int rd_len;
char buffer[1000];
int len;
char *res;
fd = open(file, O_RDONLY);
len = 0;
if(fd < 0)
return(0);
rd_len = -1;
while(rd_len)
{
rd_len = read(fd, buffer, 1000);
len+= rd_len;
}
close(fd);
res = malloc(len + 1);
if(!res)
return(0);
fd = open(file, O_RDONLY);
if(fd < 0)
return(0);
rd_len = read(fd,res, len);
res[len] = 0;
close(fd);
return(res);
}
int main(void)
{
char *input;
char *input_cpy;
char **split;
input = get_input("cur_input");
input_cpy = ft_strdup(input);
if(!input || !input_cpy)
{
fprintf(stderr, "file read error\n");
return(1);
}
split = ft_split(input, '\n');
if(!split)
return(1);
printf("result part 1: %ld\n", resolve_part1(input, split));
ft_free_str_arr(split);
split = ft_split(input_cpy, '\n');
if(!split)
return(1);
printf("result part 2: %ld\n", resolve_part2(input, split));
ft_free_str_arr(split);
free(input);
free(input_cpy);
return(0);
}

202
2025/8/part1.c Normal file
View File

@ -0,0 +1,202 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* part1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
/* Updated: 2025/12/09 19:49:03 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "libft/libft.h"
typedef struct s_conn
{
struct s_box *box;
struct s_conn *next;
} t_conn;
typedef struct s_box
{
int x;
int y;
int z;
t_conn *conn;
int exp;
} t_box;
static void parse_boxes(t_box *boxes, char **split)
{
long int i;
char *line;
i = 0;
while(split[i])
{
line = split[i];
boxes[i].x = ft_atoi(line);
while(ft_isdigit(*line))
line++;
line++;
boxes[i].y = ft_atoi(line);
while(ft_isdigit(*line))
line++;
line++;
boxes[i].z = ft_atoi(line);
i++;
}
}
static double box_dist(t_box *a, t_box *b)
{
double r;
r = pow(b->x - a->x , 2) + pow(b->y - a->y, 2) + pow(b->z - a->z, 2);
return(sqrt(r));
}
static double is_connected(t_box *a, t_box *b)
{
t_conn *tmp;
tmp = a->conn;
while(tmp)
{
if(tmp->box == b)
return(1);
tmp = tmp->next;
}
return(0);
}
static void connect_boxes(t_box *a, t_box *b)
{
t_conn *conn;
conn = malloc(sizeof(t_conn) * 2);
if(!conn)
return;
conn->box = b;
conn->next = a->conn;
a->conn = conn;
(conn + 1)->box = a;
(conn + 1)->next = b->conn;
b->conn = (conn + 1);
}
static void connect_closest(t_box *boxes, int len)
{
int i;
int j;
t_box *closest;
t_box *closest2;
double closest_dist;
i = 0;
closest = 0;
closest2 = 0;
closest_dist = 999999999999;
while(i <len)
{
j = -1;
while(++j < len)
{
if(i == j)
continue ;
if(is_connected(boxes + i, boxes + j))
continue ;
if(box_dist(boxes + i, boxes + j) < closest_dist)
{
closest = boxes + i;
closest2 = boxes + j;
closest_dist = box_dist(boxes + i, boxes + j);
}
}
i++;
}
if(!closest)
return ;
connect_boxes(closest, closest2);
}
static long int get_net_size(t_box *box)
{
long int res;
t_conn *tmp;
if(box->exp)
return(0);
box->exp = 1;
res = 1;
tmp = box->conn;
while(tmp)
{
res += get_net_size(tmp->box);
tmp = tmp->next;
}
return(res);
}
static void add_to_top(long int nb, long int *top)
{
if(nb > top[0])
{
top[2] = top[1];
top[1] = top[0];
top[0] = nb;
}
else if(nb > top[1])
{
top[1] = top[0];
top[1] = nb;
}
else if(nb > top[2])
top[2] = nb;
}
long int resolve_part1(char *input, char **split)
{
(void)input;
long int len;
t_box *boxes;
long int i;
long int tmp;
long int largest[3];
len = 0;
while(split[len])
len++;
boxes = calloc(len, sizeof(t_box));
if(!boxes)
return(0);
parse_boxes(boxes, split);
i = 0;
while(i < 1000)
{
printf("\r%ld/%d ", i + 1, 1000);
fflush(stdout);
connect_closest(boxes, len);
i++;
}
i = -1;
ft_bzero(largest, 3 * sizeof(long int));
while(++i < len)
{
if(boxes[i].exp)
continue;
tmp = get_net_size(boxes + i);
add_to_top(tmp, largest);
}
printf("\n");
return(largest[0] * largest[1] * largest[2]);
}

215
2025/8/part2.c Normal file
View File

@ -0,0 +1,215 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* part2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
/* Updated: 2025/12/09 19:47:43 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "libft/libft.h"
typedef struct s_conn
{
struct s_box *box;
struct s_conn *next;
} t_conn;
typedef struct s_box
{
long int x;
long int y;
long int z;
t_conn *conn;
int exp;
} t_box;
long int get_net_size(t_box *box)
{
long int res;
t_conn *tmp;
if(box->exp)
return(0);
box->exp = 1;
res = 1;
tmp = box->conn;
while(tmp)
{
res += get_net_size(tmp->box);
tmp = tmp->next;
}
return(res);
}
static void parse_boxes(t_box *boxes, char **split)
{
long int i;
char *line;
i = 0;
while(split[i])
{
line = split[i];
boxes[i].x = ft_atoi(line);
while(ft_isdigit(*line))
line++;
line++;
boxes[i].y = ft_atoi(line);
while(ft_isdigit(*line))
line++;
line++;
boxes[i].z = ft_atoi(line);
i++;
}
}
static double box_dist(t_box *a, t_box *b)
{
double r;
r = pow(b->x - a->x , 2) + pow(b->y - a->y, 2) + pow(b->z - a->z, 2);
return(sqrt(r));
}
static double is_connected(t_box *a, t_box *b)
{
t_conn *tmp;
tmp = a->conn;
while(tmp)
{
if(tmp->box == b)
return(1);
tmp = tmp->next;
}
return(0);
}
static void connect_boxes(t_box *a, t_box *b)
{
t_conn *conn;
conn = malloc(sizeof(t_conn) * 2);
if(!conn)
return;
conn->box = b;
conn->next = a->conn;
a->conn = conn;
(conn + 1)->box = a;
(conn + 1)->next = b->conn;
b->conn = (conn + 1);
}
static long int one_network(t_box *boxes, int len)
{
int i;
int found;
i = 0;
found = 0;
while(i < len)
{
boxes[i].exp = 0;
i++;
}
i = 0;
while(i < len)
{
if(boxes[i].exp)
{
i++;
continue;
}
if(found)
return(0);
get_net_size(boxes + i);
found = 1;
i++;
}
return(1);
}
static long int connect_closest(t_box *boxes, int len)
{
int i;
int j;
t_box *closest;
t_box *closest2;
double closest_dist;
while(!one_network(boxes, len))
{
i = 0;
closest_dist = 99999999999999;
while(i < len)
{
j = -1;
while(++j < len)
{
if(i == j)
continue ;
if(is_connected(boxes + i, boxes + j))
continue ;
if(box_dist(boxes + i, boxes + j) < closest_dist)
{
closest = boxes + i;
closest2 = boxes + j;
closest_dist = box_dist(boxes + i, boxes + j);
}
}
i++;
}
connect_boxes(closest, closest2);
}
return(closest->x * closest2->x);
}
//static void add_to_top(long int nb, long int *top)
//{
// if(nb > top[0])
// {
// top[2] = top[1];
// top[1] = top[0];
// top[0] = nb;
// }
// else if(nb > top[1])
// {
// top[1] = top[0];
// top[1] = nb;
// }
// else if(nb > top[2])
// top[2] = nb;
//
//}
long int resolve_part2(char *input, char **split)
{
(void)input;
long int len;
t_box *boxes;
long int res;
len = 0;
while(split[len])
len++;
boxes = calloc(len, sizeof(t_box));
if(!boxes)
return(0);
parse_boxes(boxes, split);
res = connect_closest(boxes, len);
return(res);
}

20
2025/8/test Normal file
View File

@ -0,0 +1,20 @@
162,817,812
57,618,57
906,360,560
592,479,940
352,342,300
466,668,158
542,29,236
431,825,988
739,650,466
52,470,668
216,146,977
819,987,18
117,168,530
805,96,715
346,949,466
970,615,88
941,993,340
862,61,35
984,92,344
425,690,689

69
2025/9/Makefile Normal file
View File

@ -0,0 +1,69 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/07/17 15:48:36 by tomoron #+# #+# #
# Updated: 2025/12/02 14:14:04 by tomoron ### ########.fr #
# #
# **************************************************************************** #
SRCS = main.c\
part1.c\
part2.c
OBJS = $(SRCS:.c=.o)
FLAGS = -Wextra -Werror -Wall -g
LIB = libft/libft.a
all: $(LIB) a.out test
cp test cur_input
./a.out
f: $(LIB) a.out input
cp input cur_input
./a.out
test:
touch test
input:
touch input
cp:
cp part1.c part2.c
sed -i 's/resolve_part1/resolve_part2/g' part2.c
$(LIB): libft
make -C libft
libft:
cp -r ../../libft .
main.c:
cp ../../main.c .
part1.c:
cp ../../part1.c .
part2.c:
cp ../../part2.c .
a.out: main.c $(OBJS) $(LIB)
clang $(FLAGS) $(OBJS) $(LIB)
clean:
rm -rf $(OBJS)
rm -rf libft
fclean: clean
rm -rf a.out
.c.o:
clang $(FLAGS) -c $< -o $@
.PHONY: t all clean fclean cp

67
2025/9/main.c Normal file
View File

@ -0,0 +1,67 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "libft/libft.h"
long int resolve_part1(char *input, char **split);
long int resolve_part2(char *input, char **split);
char *get_input(char *file)
{
int fd;
int rd_len;
char buffer[1000];
int len;
char *res;
fd = open(file, O_RDONLY);
len = 0;
if(fd < 0)
return(0);
rd_len = -1;
while(rd_len)
{
rd_len = read(fd, buffer, 1000);
len+= rd_len;
}
close(fd);
res = malloc(len + 1);
if(!res)
return(0);
fd = open(file, O_RDONLY);
if(fd < 0)
return(0);
rd_len = read(fd,res, len);
res[len] = 0;
close(fd);
return(res);
}
int main(void)
{
char *input;
char *input_cpy;
char **split;
input = get_input("cur_input");
input_cpy = ft_strdup(input);
if(!input || !input_cpy)
{
fprintf(stderr, "file read error\n");
return(1);
}
split = ft_split(input, '\n');
if(!split)
return(1);
printf("result part 1: %ld\n", resolve_part1(input, split));
ft_free_str_arr(split);
split = ft_split(input_cpy, '\n');
if(!split)
return(1);
printf("result part 2: %ld\n", resolve_part2(input, split));
ft_free_str_arr(split);
free(input);
free(input_cpy);
return(0);
}

0
2025/9/make Normal file
View File

79
2025/9/part1.c Normal file
View File

@ -0,0 +1,79 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* part1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
/* Updated: 2025/12/09 21:37:15 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include "libft/libft.h"
typedef struct s_cords
{
int x;
int y;
} t_coords;
static t_coords parse_line(char *line)
{
t_coords res;
res.x = atoi(line);
while(ft_isdigit(*line))
line++;
line++;
res.y = atoi(line);
return(res);
}
static long int get_biggest_area(t_coords *co, int len)
{
int i;
int j;
long int max;
long int tmp;
i = 0;
max = 0;
while(i < len)
{
j = -1;
while(++j < len)
{
if(i == j)
continue;
tmp = ((long)abs(co[i].x - co[j].x) + 1) * ((long)abs(co[i].y - co[j].y) + 1);
if(tmp > max)
max = tmp;
}
i++;
}
return(max);
}
long int resolve_part1(char *input, char **split)
{
(void)input;
int len;
t_coords *co;
int i;
len = 0;
while(split[len])
len++;
co = malloc(len * sizeof(t_coords));
i = 0;
while(split[i])
{
co[i] = parse_line(split[i]);
i++;
}
return(get_biggest_area(co, len));
}
// 2147308956 <

166
2025/9/part2.c Normal file
View File

@ -0,0 +1,166 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* part2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
/* Updated: 2025/12/10 15:08:17 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "libft/libft.h"
typedef struct s_cords
{
double x;
double y;
} t_coords;
static t_coords parse_line(char *line)
{
t_coords res;
res.x = atoi(line);
while(ft_isdigit(*line))
line++;
line++;
res.y = atoi(line);
return(res);
}
static int is_point_on_line(t_coords pos, t_coords a, t_coords b)
{
double cross = (pos.x - a.x) * (b.y - a.y) - (pos.y - a.y) * (b.x - a.x);
if(cross != 0)
return(0);
return(pos.x >= fmin(a.x, b.x) && pos.x <= fmax(a.x, b.x) &&
pos.y >= fmin(a.y, b.y) && pos.y <= fmax(a.y, b.y));
}
static int is_point_in_poly(t_coords pos, t_coords *poly, int len)
{
int inside;
int i;
t_coords cur[2];
double intersect;
inside = 0;
i = 0;
while(i < len)
{
cur[0] = poly[i];
cur[1] = poly[(i + 1) % len];
if(is_point_on_line(pos, cur[0], cur[1]))
{
inside = 1;
break;
}
if((cur[0].y > pos.y) != (cur[1].y > pos.y))
{
intersect = ((cur[1].x - cur[0].x) * (pos.y - cur[0].y)) / (cur[1].y - cur[0].y) + cur[0].x;
if(pos.x < intersect)
inside = !inside;
}
i++;
}
return(inside);
}
static int is_line_in_poly(t_coords p1, t_coords p2, t_coords *poly, int len)
{
t_coords from;
t_coords to;
from.x = fmin(p1.x, p2.x);
from.y = fmin(p1.y, p2.y);
to.x = fmax(p1.x, p2.x);
to.y = fmax(p1.y, p2.y);
while(from.x <= to.x && from.y <= to.y)
{
if(!is_point_in_poly(from, poly, len))
{
return(0);
}
if(from.x != to.x)
from.x++;
else
from.y++;
}
return(1);
}
static int is_all_in_poly(t_coords p1, t_coords p2, t_coords *poly, int len)
{
if(!is_line_in_poly(p1,(t_coords){p2.x, p1.y}, poly, len) ||
!is_line_in_poly((t_coords){p2.x, p1.y}, p2, poly, len) ||
!is_line_in_poly(p2, (t_coords){p1.x, p2.y}, poly, len) ||
!is_line_in_poly((t_coords){p1.x, p2.y},p1, poly, len))
return(0);
return(1);
}
static long int get_biggest_area(t_coords *co, int len)
{
int i;
int j;
long int max;
long int tmp;
i = 0;
max = 0;
while(i < len)
{
j = i;
while(++j < len)
{
if(i == j)
continue;
tmp = ((long)fabs(co[i].x - co[j].x) + 1) * ((long)fabs(co[i].y - co[j].y) + 1);
if(tmp <= max)
continue;
if(!is_point_in_poly((t_coords){co[i].x,co[j].y}, co, len) || !is_point_in_poly((t_coords){co[j].x,co[i].y}, co, len))
continue;
if(!is_all_in_poly(co[i], co[j], co, len))
continue;
printf("got %ld for %.0f, %.0f to %.0f, %.0f checking points \n", tmp, co[i].x, co[i].y, co[j].x, co[j].y);
max = tmp;
}
i++;
}
return(max);
}
long int resolve_part2(char *input, char **split)
{
(void)input;
int len;
t_coords *co;
int i;
len = 0;
while(split[len])
len++;
co = malloc(len * sizeof(t_coords));
i = 0;
while(split[i])
{
co[i] = parse_line(split[i]);
i++;
}
return(get_biggest_area(co, len));
}
// 4604141472 >
// 4604141472 :/
// 4501110590 >
// 1588990708

8
2025/9/test Normal file
View File

@ -0,0 +1,8 @@
7,1
11,1
11,7
9,7
9,5
2,5
2,3
7,3