En realitat és la primera part del puzzle
This commit is contained in:
43
aoc_25_1_1/src/aoc25.c
Normal file
43
aoc_25_1_1/src/aoc25.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user