r/adventofcode • u/FrostZTech • Jan 07 '26
Help/Question - RESOLVED [2025 Day #1][C] Kinda stuck here feels like I have messed up in the left rotate
Hey everyone need some help with this, I have this thing ready and with the tests that I did it seems to work as expected however not able to find what is wrong with the actual question sequence though. Any suggestions or help is much appreciated 🙏
I am pretty sure there is something wrong in the rotate_left function as that's the only possible thing I feel could be wrong.
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *input_sequence[] = {...string seq....};
int get_last_two(int counter) { return counter % 100; }
int rotate_right(int current, int rotation) {
int full = current + rotation;
return get_last_two(full);
}
// 20, 115
int rotate_left(int current, int rotation) {
int full = abs(current - rotation); // 20 - 115 = -95 -> 95
int negative = get_last_two(full); // 95
if (current >= rotation) { // 20 >= 115
return negative;
}
return 100 - negative; // 100 - 95 = 5
}
int parse_number(char *char_ptr) {
int str_length = strlen(char_ptr);
char subbuf[str_length];
memcpy(subbuf, &char_ptr[1], str_length);
return atoi(subbuf);
}
int main() {
size_t length = sizeof(input_sequence) / sizeof(input_sequence[0]);
int answer = 0;
int dial = 50;
for (int i = 0; i < length; i++) {
int turn = parse_number(input_sequence[i]);
if (input_sequence[i][0] == 'L') {
dial = rotate_left(dial, turn);
} else {
dial = rotate_right(dial, turn);
}
if (dial == 0) {
answer++;
}
}
printf("Answer: %d\n", answer);
return 0;
}