diff --git a/d08/run.py b/d08/run.py new file mode 100644 index 0000000..7b4d442 --- /dev/null +++ b/d08/run.py @@ -0,0 +1,22 @@ +import sys +from itertools import cycle +from math import lcm + +I, _, *P = [l for l in sys.stdin.read().splitlines()] +# 0000000000111111111 +# 0123456789012345678 +# BCN = (HFN, KFC) +P = {l[0:3]:(l[7:10],l[12:15]) for l in P} + +def countsteps(g): + C = g + N = 0 + for i in cycle(I): + if C[2] == 'Z': + break + C = P[C][i == 'R'] + N += 1 + return N + +print("part 1:", countsteps("AAA")) +print("part 2:", lcm(*(countsteps(p) for p in P.keys() if p[2] == 'A')))