summaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-12-08 14:40:42 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-12-08 14:40:42 +0100
commit0dc456e1a476090ff8726d9a276054f226e31486 (patch)
tree27f4c3036f29cb6f84814fbf50ac4ff19838f45b /prog
parentaoc7 (diff)
downloadr-0dc456e1a476090ff8726d9a276054f226e31486.tar
r-0dc456e1a476090ff8726d9a276054f226e31486.tar.gz
r-0dc456e1a476090ff8726d9a276054f226e31486.tar.bz2
r-0dc456e1a476090ff8726d9a276054f226e31486.tar.lz
r-0dc456e1a476090ff8726d9a276054f226e31486.tar.xz
r-0dc456e1a476090ff8726d9a276054f226e31486.tar.zst
r-0dc456e1a476090ff8726d9a276054f226e31486.zip
Diffstat (limited to 'prog')
-rwxr-xr-xprog/aoc/23/8/1.py43
-rw-r--r--prog/aoc/23/8/1.txt9
-rw-r--r--prog/aoc/23/8/2.txt5
-rw-r--r--prog/aoc/23/8/3.txt10
4 files changed, 67 insertions, 0 deletions
diff --git a/prog/aoc/23/8/1.py b/prog/aoc/23/8/1.py
new file mode 100755
index 0000000..9ff0113
--- /dev/null
+++ b/prog/aoc/23/8/1.py
@@ -0,0 +1,43 @@
+#!/usr/bin/python3
+inst = input()
+input()
+graph = {}
+try:
+ while True:
+ a = input().split(" = ")
+ graph[a[0]] = a[1].replace("(", "").replace(")", "").split(", ")
+except EOFError:
+ pass
+cur = "AAA"
+runs = 0
+while True:
+ for d in inst:
+ if cur == "ZZZ":
+ break
+ if d == "L":
+ cur = graph[cur][0]
+ else:
+ cur = graph[cur][1]
+ runs += 1
+ else:
+ continue
+ break
+print(runs)
+r = []
+for s in [x for x in graph if x[2] == "A"]:
+ runs = 0
+ while True:
+ for d in inst:
+ if s[2] == "Z":
+ break
+ if d == "L":
+ s = graph[s][0]
+ else:
+ s = graph[s][1]
+ runs += 1
+ else:
+ continue
+ break
+ r.append(runs)
+from math import lcm
+print(lcm(*r))
diff --git a/prog/aoc/23/8/1.txt b/prog/aoc/23/8/1.txt
new file mode 100644
index 0000000..9029a1b
--- /dev/null
+++ b/prog/aoc/23/8/1.txt
@@ -0,0 +1,9 @@
+RL
+
+AAA = (BBB, CCC)
+BBB = (DDD, EEE)
+CCC = (ZZZ, GGG)
+DDD = (DDD, DDD)
+EEE = (EEE, EEE)
+GGG = (GGG, GGG)
+ZZZ = (ZZZ, ZZZ)
diff --git a/prog/aoc/23/8/2.txt b/prog/aoc/23/8/2.txt
new file mode 100644
index 0000000..7d1b58d
--- /dev/null
+++ b/prog/aoc/23/8/2.txt
@@ -0,0 +1,5 @@
+LLR
+
+AAA = (BBB, BBB)
+BBB = (AAA, ZZZ)
+ZZZ = (ZZZ, ZZZ)
diff --git a/prog/aoc/23/8/3.txt b/prog/aoc/23/8/3.txt
new file mode 100644
index 0000000..5b3fa58
--- /dev/null
+++ b/prog/aoc/23/8/3.txt
@@ -0,0 +1,10 @@
+LR
+
+11A = (11B, XXX)
+11B = (XXX, 11Z)
+11Z = (11B, XXX)
+22A = (22B, XXX)
+22B = (22C, 22C)
+22C = (22Z, 22Z)
+22Z = (22B, 22B)
+XXX = (XXX, XXX)