summaryrefslogtreecommitdiffstats
path: root/prog/aoc/23/8/1.py
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-12-08 20:17:50 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-12-08 20:17:50 +0100
commita7d227edcbeefbeb37df118664ac9b202bb064fd (patch)
tree6e98d5b71606db0ba68001b54fbd0c67fac8b31c /prog/aoc/23/8/1.py
parentnew research (diff)
parentaoc8 (diff)
downloadr-a7d227edcbeefbeb37df118664ac9b202bb064fd.tar
r-a7d227edcbeefbeb37df118664ac9b202bb064fd.tar.gz
r-a7d227edcbeefbeb37df118664ac9b202bb064fd.tar.bz2
r-a7d227edcbeefbeb37df118664ac9b202bb064fd.tar.lz
r-a7d227edcbeefbeb37df118664ac9b202bb064fd.tar.xz
r-a7d227edcbeefbeb37df118664ac9b202bb064fd.tar.zst
r-a7d227edcbeefbeb37df118664ac9b202bb064fd.zip
Diffstat (limited to 'prog/aoc/23/8/1.py')
-rwxr-xr-xprog/aoc/23/8/1.py43
1 files changed, 43 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))