From f13197e2a519d7342fb06b0c6b4b3f026b602e9d Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sun, 18 Dec 2022 13:07:49 +0000 Subject: 16 intern later to compact node ids --- 16.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/16.py b/16.py index 24429a7..42f11d0 100644 --- a/16.py +++ b/16.py @@ -25,22 +25,22 @@ with open_day(16) as f: m = regex.match(line) assert(m) valve, flow, neighbours = m.group(1, 2, 3) - inp[intern(valve)] = (int(flow), [intern(n) for n in neighbours.split(', ')]) + inp[valve] = (int(flow), neighbours.split(', ')) nodes = {} for valve, (flow, neighbours) in inp.items(): - if valve != 0 and flow == 0: continue + if valve != 'AA' and flow == 0: continue actual_neighbours = [] for n in neighbours: prev = valve for cost in count(1): - if n == 0 or inp[n][0] != 0: break + if n == 'AA' or inp[n][0] != 0: break l, r = inp[n][1] nnext = r if l == prev else l prev = n n = nnext - actual_neighbours.append((n, cost)) - nodes[valve] = Node(flow, actual_neighbours) + actual_neighbours.append((intern(n), cost)) + nodes[intern(valve)] = Node(flow, actual_neighbours) @cache def sum_flow(open_valves): -- cgit v1.2.3-54-g00ecf