19-1
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
import re
|
||||||
|
blueprint_re = re.compile(r'Blueprint (\d+): Each ore robot costs (\d+) ore. Each clay robot costs (\d+) ore. Each obsidian robot costs (\d+) ore and (\d+) clay. Each geode robot costs (\d+) ore and (\d+) obsidian.')
|
||||||
|
|
||||||
|
with open('input') as file:
|
||||||
|
bps = [tuple(map(int, blueprint_re.match(x).groups())) for x in file.read().strip().split('\n')]
|
||||||
|
|
||||||
|
def quality_level(n, cor, ccl, coob, ccob, corg, cobg):
|
||||||
|
def next_minute(m, ore, cla, obs, geo, nor, ncl, nob, nge, bor, bcl, bob, bge):
|
||||||
|
nonlocal max_geo
|
||||||
|
ore += nor
|
||||||
|
cla += ncl
|
||||||
|
obs += nob
|
||||||
|
geo += nge
|
||||||
|
if bor>0:
|
||||||
|
bor -= 1
|
||||||
|
if bor==0:
|
||||||
|
nor += 1
|
||||||
|
if bcl>0:
|
||||||
|
bcl -= 1
|
||||||
|
if bcl==0:
|
||||||
|
ncl += 1
|
||||||
|
if bob>0:
|
||||||
|
bob -= 1
|
||||||
|
if bob==0:
|
||||||
|
nob += 1
|
||||||
|
if bge>0:
|
||||||
|
bge -= 1
|
||||||
|
if bge==0:
|
||||||
|
nge += 1
|
||||||
|
if m>=24:
|
||||||
|
if max_geo<geo:
|
||||||
|
print(geo)
|
||||||
|
max_geo=geo
|
||||||
|
return
|
||||||
|
if bor==bcl==bob==bge==0:
|
||||||
|
if ore>=cor:
|
||||||
|
next_minute(m+1, ore-cor, cla, obs, geo, nor, ncl, nob, nge, 1, 0, 0, 0)
|
||||||
|
if ore>=ccl:
|
||||||
|
next_minute(m+1, ore-ccl, cla, obs, geo, nor, ncl, nob, nge, 0, 1, 0, 0)
|
||||||
|
if ore>=coob and cla>=ccob:
|
||||||
|
next_minute(m+1, ore-coob, cla-ccob, obs, geo, nor, ncl, nob, nge, 0, 0, 1, 0)
|
||||||
|
if ore>=corg and obs>=cobg:
|
||||||
|
next_minute(m+1, ore-corg, cla, obs-cobg, geo, nor, ncl, nob, nge, 0, 0, 0, 1)
|
||||||
|
next_minute(m+1, ore, cla, obs, geo, nor, ncl, nob, nge, bor, bcl, bob, bge)
|
||||||
|
max_geo = 0
|
||||||
|
next_minute(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)
|
||||||
|
return n*max_geo
|
||||||
|
|
||||||
|
print(sum(quality_level(*bp) for bp in bps))
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
Blueprint 1: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 20 clay. Each geode robot costs 4 ore and 7 obsidian.
|
||||||
|
Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 2 ore. Each obsidian robot costs 2 ore and 17 clay. Each geode robot costs 2 ore and 10 obsidian.
|
||||||
|
Blueprint 3: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 18 clay. Each geode robot costs 2 ore and 19 obsidian.
|
||||||
|
Blueprint 4: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 18 clay. Each geode robot costs 4 ore and 11 obsidian.
|
||||||
|
Blueprint 5: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 10 clay. Each geode robot costs 3 ore and 14 obsidian.
|
||||||
|
Blueprint 6: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 15 clay. Each geode robot costs 2 ore and 13 obsidian.
|
||||||
|
Blueprint 7: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 11 clay. Each geode robot costs 3 ore and 8 obsidian.
|
||||||
|
Blueprint 8: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 16 clay. Each geode robot costs 2 ore and 15 obsidian.
|
||||||
|
Blueprint 9: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 15 clay. Each geode robot costs 3 ore and 7 obsidian.
|
||||||
|
Blueprint 10: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 16 clay. Each geode robot costs 3 ore and 13 obsidian.
|
||||||
|
Blueprint 11: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 17 clay. Each geode robot costs 3 ore and 11 obsidian.
|
||||||
|
Blueprint 12: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 11 clay. Each geode robot costs 2 ore and 16 obsidian.
|
||||||
|
Blueprint 13: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 10 clay. Each geode robot costs 3 ore and 10 obsidian.
|
||||||
|
Blueprint 14: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 8 clay. Each geode robot costs 2 ore and 15 obsidian.
|
||||||
|
Blueprint 15: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 19 clay. Each geode robot costs 4 ore and 11 obsidian.
|
||||||
|
Blueprint 16: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 17 clay. Each geode robot costs 4 ore and 20 obsidian.
|
||||||
|
Blueprint 17: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 19 clay. Each geode robot costs 4 ore and 8 obsidian.
|
||||||
|
Blueprint 18: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 9 clay. Each geode robot costs 3 ore and 7 obsidian.
|
||||||
|
Blueprint 19: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 7 clay. Each geode robot costs 2 ore and 7 obsidian.
|
||||||
|
Blueprint 20: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 13 clay. Each geode robot costs 2 ore and 9 obsidian.
|
||||||
|
Blueprint 21: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 13 clay. Each geode robot costs 2 ore and 20 obsidian.
|
||||||
|
Blueprint 22: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 9 clay. Each geode robot costs 3 ore and 9 obsidian.
|
||||||
|
Blueprint 23: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 18 clay. Each geode robot costs 4 ore and 9 obsidian.
|
||||||
|
Blueprint 24: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 5 clay. Each geode robot costs 4 ore and 8 obsidian.
|
||||||
|
Blueprint 25: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 14 clay. Each geode robot costs 3 ore and 16 obsidian.
|
||||||
|
Blueprint 26: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 20 clay. Each geode robot costs 2 ore and 10 obsidian.
|
||||||
|
Blueprint 27: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 15 clay. Each geode robot costs 4 ore and 9 obsidian.
|
||||||
|
Blueprint 28: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 15 clay. Each geode robot costs 2 ore and 8 obsidian.
|
||||||
|
Blueprint 29: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 13 clay. Each geode robot costs 3 ore and 19 obsidian.
|
||||||
|
Blueprint 30: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 18 clay. Each geode robot costs 4 ore and 20 obsidian.
|
||||||
Reference in New Issue
Block a user