change Makefile and add day 2
This commit is contained in:
79
2025/2/part2.c
Normal file
79
2025/2/part2.c
Normal file
@ -0,0 +1,79 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* part2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
|
||||
/* Updated: 2025/12/03 16:31:23 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libft/libft.h"
|
||||
|
||||
static long int is_rep(long int nb_int)
|
||||
{
|
||||
char nb[100];
|
||||
char search[100];
|
||||
int len;
|
||||
int cur_len;
|
||||
char *cur;
|
||||
|
||||
len = sprintf(nb, "%ld", nb_int);
|
||||
cur_len = 1;
|
||||
while(cur_len <= len / 2)
|
||||
{
|
||||
strncpy(search, nb, cur_len);
|
||||
search[cur_len] = 0;
|
||||
cur = nb + cur_len;
|
||||
while(cur - nb <= len)
|
||||
{
|
||||
if(!ft_strnstr(cur, search, cur_len))
|
||||
break;
|
||||
cur += cur_len;
|
||||
}
|
||||
if(cur - nb >= len)
|
||||
return(nb_int);
|
||||
cur_len++;
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
long int resolve_part2(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