aboutsummaryrefslogtreecommitdiff
path: root/2023/08/8a.c
diff options
context:
space:
mode:
Diffstat (limited to '2023/08/8a.c')
-rw-r--r--2023/08/8a.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/2023/08/8a.c b/2023/08/8a.c
new file mode 100644
index 0000000..62f6fcd
--- /dev/null
+++ b/2023/08/8a.c
@@ -0,0 +1,35 @@
1#include <inttypes.h>
2#include <math.h>
3#include <stdbool.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8#define N 30000
9
10bool isnum(char c) { return c >= '0' && c <= '9'; }
11int index(char *c) { return c[0]-'A' + (c[1]-'A' + (c[2]-'A')*26)*26; }
12
13int map[N][2];
14
15int main() {
16 char *buf, dir[N], line[N];
17 int n, i, s;
18
19 n = strlen(fgets(dir, N, stdin)) - 1;
20
21 fgets(line, N, stdin);
22 while ((buf = fgets(line, N, stdin)) != NULL) {
23 i = index(buf);
24 while (*buf != '(') buf++;
25 map[i][0] = index(buf+1);
26 while (*buf != ' ') buf++;
27 map[i][1] = index(buf+1);
28 }
29
30 for (i = index("AAA"), s = 0; i != index("ZZZ"); s++)
31 i = map[i][dir[s % n] == 'R'];
32
33 printf("%d\n", s);
34 return 0;
35}

Generated with cgit - Back to sebastiano.tronto.net