1
0

En realitat és la primera part del puzzle

This commit is contained in:
2025-12-02 23:55:10 +01:00
parent a75bc0f7ca
commit 3cb5ff77cc
6 changed files with 2 additions and 2 deletions

2
aoc_25_1_1/Makefile Normal file
View 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

File diff suppressed because it is too large Load Diff

43
aoc_25_1_1/src/aoc25.c Normal file
View 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
View 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
View 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
View 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