diff options
author | Marvin Borner | 2023-12-08 13:23:17 +0100 |
---|---|---|
committer | Marvin Borner | 2023-12-08 13:23:17 +0100 |
commit | 3a66da513f561e79aecce9c1a470ad34442bc675 (patch) | |
tree | 0833e7b7ac27a18e4d98ad66658f93128247c074 | |
parent | b91f98d22111f30c3b27fe1b20e8da05465fb6c2 (diff) |
Initial
-rw-r--r-- | 2023/08/solve.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/2023/08/solve.py b/2023/08/solve.py new file mode 100644 index 0000000..61742f4 --- /dev/null +++ b/2023/08/solve.py @@ -0,0 +1,34 @@ +L = [l.strip() for l in open("input").readlines()] + +path = L[0] +nodes = dict( + (p := n.split(" = ")) and (p[0], p[1][1:-1].split(", ")) for n in L[2:] +) + + +def part1(): + steps = 0 + curr = "AAA" + while True: + d = path[steps % len(path)] + curr = nodes[curr][0 if d == "L" else 1] + steps += 1 + if curr == "ZZZ": + return steps + + +def part2(): + steps = 0 + curr = [k for k in nodes.keys() if k[2] == "A"] + para = len(curr) + while True: + d = path[steps % len(path)] + for i in range(para): + curr[i] = nodes[curr[i]][0 if d == "L" else 1] + steps += 1 + if len([k for k in curr if k[2] == "Z"]) == para: + return steps + + +# print(part1()) +print(part2()) |