add day 9 (a bit slow)
This commit is contained in:
79
2025/9/part1.c
Normal file
79
2025/9/part1.c
Normal 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 <
|
||||
Reference in New Issue
Block a user