Skip to content

Commit

Permalink
2022 Day 16 little faster, still slow
Browse files Browse the repository at this point in the history
  • Loading branch information
TedCassirer committed Jan 5, 2023
1 parent da6482b commit f971ffe
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions aoc_cas/aoc2022/day16.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ def estimate(flowRates, time, toVisit):


def search(graph, flowRates, time, toVisit):
seen = defaultdict(int)
seen = set()
toSearch = [(-1, 0, time, "AA", toVisit)]
maxPressureLost = 0
while toSearch:
e, pressureLost, time, cur, toVisit = heapq.heappop(toSearch)
maxPressureLost = max(maxPressureLost, -pressureLost)
key = (cur, toVisit)
if seen[key] >= -e:
if key in seen:
continue
seen[key] = -e
seen.add(key)
for p2 in toVisit:
steps = graph[cur][p2]
if steps >= time:
Expand All @@ -79,13 +79,13 @@ def part1(data):
def part2(data):
graph, flowRates = buildGraph(data)
maxFlowLost = 0
for groupSize in range(len(flowRates) // 2 - 1, len(flowRates) // 2 + 1):
for g1 in combinations(flowRates, groupSize):
g1 = frozenset(g1)
g2 = frozenset(flowRates.keys() - g1)
pl1 = search(graph, flowRates, 26, g1)
pl2 = search(graph, flowRates, 26, g2)
maxFlowLost = max(maxFlowLost, pl1 + pl2)
groupSize = len(flowRates) // 2
for g1 in combinations(flowRates, groupSize):
g1 = frozenset(g1)
g2 = frozenset(flowRates.keys() - g1)
pl1 = search(graph, flowRates, 26, g1)
pl2 = search(graph, flowRates, 26, g2)
maxFlowLost = max(maxFlowLost, pl1 + pl2)
return maxFlowLost


Expand Down

0 comments on commit f971ffe

Please sign in to comment.