change Makefile and add day 2
This commit is contained in:
71
2025/2/part1.c
Normal file
71
2025/2/part1.c
Normal file
@ -0,0 +1,71 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* part1.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
|
||||
/* Updated: 2025/12/03 16:31:41 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "libft/libft.h"
|
||||
|
||||
static long int is_rep(long int nb)
|
||||
{
|
||||
long int tmp;
|
||||
int len;
|
||||
long int div;
|
||||
|
||||
tmp = nb;
|
||||
len = 1;
|
||||
while(tmp > 9)
|
||||
{
|
||||
tmp /= 10;
|
||||
len++;
|
||||
}
|
||||
|
||||
div = pow(10, len / 2);
|
||||
if (nb / div == nb % div)
|
||||
return(nb);
|
||||
return(0);
|
||||
}
|
||||
|
||||
long int resolve_part1(char *input, char **split)
|
||||
{
|
||||
(void)split;
|
||||
long int start;
|
||||
long int end;
|
||||
long int res;
|
||||
|
||||
res = 0;
|
||||
while(*input)
|
||||
{
|
||||
start = atol(input);
|
||||
while(ft_isdigit(*input))
|
||||
input++;
|
||||
input++;
|
||||
end = atol(input);
|
||||
while(ft_isdigit(*input))
|
||||
input++;
|
||||
input++;
|
||||
|
||||
if(start > end)
|
||||
{
|
||||
res = start;
|
||||
start = end;
|
||||
end = res;
|
||||
}
|
||||
|
||||
while(start <= end)
|
||||
{
|
||||
res += is_rep(start);
|
||||
start++;
|
||||
}
|
||||
}
|
||||
return(res);
|
||||
}
|
||||
Reference in New Issue
Block a user