Files
aoc/2025/1/part2.c
2025-12-01 10:47:46 +01:00

56 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* part2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
/* Updated: 2025/12/01 10:43:09 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include "libft/libft.h"
int change_val(long int *val, int step)
{
*val += step;
if(*val > 99)
*val = 0;
if(*val < 0)
*val = 99;
if(*val == 0)
return(1);
return(0);
}
long int resolve_part2(char *input, char **split)
{
(void)input;
int move_val;
long int cur_val;
long int res;
cur_val = 50;
res = 0;
while(*split)
{
move_val = ft_atoi((*split) + 1);
if(**split == 'L')
{
while (move_val--)
res += change_val(&cur_val, -1);
}
else
{
while (move_val--)
res += change_val(&cur_val, 1);
}
split++;
}
return(res);
}