diff --git a/day08.py b/day08.py index 6036651..1613592 100644 --- a/day08.py +++ b/day08.py @@ -46,20 +46,20 @@ class Day(AOCDay): inst, nodes = self.parse_input() i_len = len(inst) check_nodes = [x for x in nodes if x.endswith("A")] - nodes_dp = defaultdict(dict) + z_steps = [] for node in check_nodes: cur_step = 0 cur_node = node - while (cur_node, cur_step % i_len) not in nodes_dp[node]: - nodes_dp[node][(cur_node, cur_step % i_len)] = cur_step + while not cur_node.endswith("Z"): if inst[cur_step % i_len] == "L": cur_node = nodes[cur_node][0] else: cur_node = nodes[cur_node][1] cur_step += 1 + z_steps.append(cur_step) - return math.lcm(*[v for node in check_nodes for k, v in nodes_dp[node].items() if k[0].endswith("Z")]) + return math.lcm(*z_steps) if __name__ == "__main__":