day 19 part 2 solve
parent
c572351a00
commit
ee05144644
19
day19/sol.py
19
day19/sol.py
|
@ -27,7 +27,7 @@ def parse(line):
|
||||||
'geode': [ore4,0,obs4,0],
|
'geode': [ore4,0,obs4,0],
|
||||||
}
|
}
|
||||||
|
|
||||||
def simulate(blueprint):
|
def simulate(blueprint, minutes=24):
|
||||||
B = blueprint
|
B = blueprint
|
||||||
resources = [0]*4
|
resources = [0]*4
|
||||||
robots = [1,0,0,0]
|
robots = [1,0,0,0]
|
||||||
|
@ -51,7 +51,6 @@ def simulate(blueprint):
|
||||||
|
|
||||||
print(B_items)
|
print(B_items)
|
||||||
|
|
||||||
minutes = 24
|
|
||||||
buckets = [[] for _ in range(minutes+1)]
|
buckets = [[] for _ in range(minutes+1)]
|
||||||
def enqueue(t, robots, resources):
|
def enqueue(t, robots, resources):
|
||||||
if t < 0 or t >= len(buckets):
|
if t < 0 or t >= len(buckets):
|
||||||
|
@ -82,7 +81,7 @@ def simulate(blueprint):
|
||||||
#next = [[] for _ in range(4)]
|
#next = [[] for _ in range(4)]
|
||||||
buckets[minutes].sort(reverse=True)
|
buckets[minutes].sort(reverse=True)
|
||||||
print(minutes, buckets[minutes][:1])
|
print(minutes, buckets[minutes][:1])
|
||||||
for _, robots, resources in buckets[minutes]:
|
for _, robots, resources in buckets[minutes][:100000]:
|
||||||
can_build = 0
|
can_build = 0
|
||||||
if robots[3]:
|
if robots[3]:
|
||||||
geodes = robots[3]*minutes + resources[3]
|
geodes = robots[3]*minutes + resources[3]
|
||||||
|
@ -126,6 +125,7 @@ def simulate(blueprint):
|
||||||
#count = sum(len(b) for b in next)
|
#count = sum(len(b) for b in next)
|
||||||
#print(count, q[:1])
|
#print(count, q[:1])
|
||||||
print(minutes, [len(x) for x in buckets])
|
print(minutes, [len(x) for x in buckets])
|
||||||
|
buckets[minutes] = []
|
||||||
|
|
||||||
minutes -= 1
|
minutes -= 1
|
||||||
|
|
||||||
|
@ -153,6 +153,15 @@ def solve(input):
|
||||||
print(t)
|
print(t)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
assert solve(sample) == 33
|
def solve2(input):
|
||||||
solve(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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue