From ee05144644011e0fe062c256a5c30b01fe795377 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Mon, 19 Dec 2022 11:15:09 -0800 Subject: [PATCH] day 19 part 2 solve --- day19/sol.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/day19/sol.py b/day19/sol.py index 36fa717..09f89f4 100644 --- a/day19/sol.py +++ b/day19/sol.py @@ -27,7 +27,7 @@ def parse(line): 'geode': [ore4,0,obs4,0], } -def simulate(blueprint): +def simulate(blueprint, minutes=24): B = blueprint resources = [0]*4 robots = [1,0,0,0] @@ -51,7 +51,6 @@ def simulate(blueprint): print(B_items) - minutes = 24 buckets = [[] for _ in range(minutes+1)] def enqueue(t, robots, resources): if t < 0 or t >= len(buckets): @@ -82,7 +81,7 @@ def simulate(blueprint): #next = [[] for _ in range(4)] buckets[minutes].sort(reverse=True) print(minutes, buckets[minutes][:1]) - for _, robots, resources in buckets[minutes]: + for _, robots, resources in buckets[minutes][:100000]: can_build = 0 if robots[3]: geodes = robots[3]*minutes + resources[3] @@ -126,6 +125,7 @@ def simulate(blueprint): #count = sum(len(b) for b in next) #print(count, q[:1]) print(minutes, [len(x) for x in buckets]) + buckets[minutes] = [] minutes -= 1 @@ -153,6 +153,15 @@ def solve(input): print(t) return t -assert solve(sample) == 33 -solve(input) +def solve2(input): + t = 1 + for idx, B in input.items(): + if idx <= 3: + g = simulate(B, minutes=32) + t *= g + print(t) + return t + +#assert solve(sample) == 33 +solve2(input)