En realitat és la primera part del puzzle
This commit is contained in:
2
aoc_25_1_1/Makefile
Normal file
2
aoc_25_1_1/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
build:
|
||||
gcc -g src/aoc25.c src/*.s -o out_a64
|
||||
4136
aoc_25_1_1/aoc25_1_1.txt
Normal file
4136
aoc_25_1_1/aoc25_1_1.txt
Normal file
File diff suppressed because it is too large
Load Diff
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);
|
||||
}
|
||||
12
aoc_25_1_1/src/count.s
Normal file
12
aoc_25_1_1/src/count.s
Normal file
@@ -0,0 +1,12 @@
|
||||
.global count
|
||||
.type count, "function"
|
||||
.p2align 4
|
||||
|
||||
count:
|
||||
cmp w1, #0
|
||||
b.eq count1
|
||||
b finish
|
||||
count1:
|
||||
add w0, w0, #1
|
||||
finish:
|
||||
ret
|
||||
17
aoc_25_1_1/src/left.s
Normal file
17
aoc_25_1_1/src/left.s
Normal file
@@ -0,0 +1,17 @@
|
||||
.global left
|
||||
.type left, "function"
|
||||
.p2align 4
|
||||
|
||||
left:
|
||||
subs w0, w0, #1
|
||||
b.lt loop99
|
||||
b left1
|
||||
left1:
|
||||
subs w1, w1, #1
|
||||
b.eq finish
|
||||
b left
|
||||
loop99:
|
||||
mov w0, #99
|
||||
b left1
|
||||
finish:
|
||||
ret
|
||||
18
aoc_25_1_1/src/right.s
Normal file
18
aoc_25_1_1/src/right.s
Normal file
@@ -0,0 +1,18 @@
|
||||
.global right
|
||||
.type right, "function"
|
||||
.p2align 4
|
||||
|
||||
right:
|
||||
adds w0, w0, #1
|
||||
cmp w0, #99
|
||||
b.gt loop0
|
||||
b right1
|
||||
right1:
|
||||
subs w1, w1, #1
|
||||
b.eq finish
|
||||
b right
|
||||
loop0:
|
||||
mov w0, #0
|
||||
b right1
|
||||
finish:
|
||||
ret
|
||||
Reference in New Issue
Block a user