44 lines
991 B
C
44 lines
991 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
extern int left(int a, int b);
|
|
extern int right(int a, int b);
|
|
extern int count(int a, int b);
|
|
|
|
int main(void) {
|
|
int dial = 50;
|
|
int rotation;
|
|
char direction[2];
|
|
int password = 0;
|
|
|
|
FILE *fptr = fopen("aoc25_1_1.txt", "r");
|
|
|
|
if (fptr == NULL) {
|
|
printf("Error, puzzle input aoc25_1_1.txt not found\n");
|
|
return (1);
|
|
}
|
|
|
|
printf("DIAL starts at %d\n", dial);
|
|
|
|
while (fscanf(fptr, "%s %d", direction, &rotation) == 2) {
|
|
printf("DIRECTION %s ROTATION %d\n", direction, rotation);
|
|
|
|
if (strcmp(direction, "L") == 0) {
|
|
dial = left(dial, rotation);
|
|
printf("DIAL is now %d\n", dial);
|
|
}
|
|
|
|
if (strcmp(direction, "R") == 0) {
|
|
dial = right(dial, rotation);
|
|
printf("DIAL is now %d\n", dial);
|
|
}
|
|
|
|
password = count(password, dial);
|
|
printf("PASSWORD is now %d\n", password);
|
|
}
|
|
|
|
fclose(fptr);
|
|
|
|
return (0);
|
|
}
|