day 19 wip
parent
88040394db
commit
fd84db7072
|
@ -0,0 +1,30 @@
|
|||
Blueprint 1: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 13 clay. Each geode robot costs 3 ore and 7 obsidian.
|
||||
Blueprint 2: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 20 clay. Each geode robot costs 2 ore and 12 obsidian.
|
||||
Blueprint 3: 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 4: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 18 clay. Each geode robot costs 2 ore and 11 obsidian.
|
||||
Blueprint 5: 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 6: 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 3 ore and 14 obsidian.
|
||||
Blueprint 7: 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 8: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 14 clay. Each geode robot costs 4 ore and 19 obsidian.
|
||||
Blueprint 9: 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 10: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 19 clay. Each geode robot costs 3 ore and 17 obsidian.
|
||||
Blueprint 11: 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 12: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 17 clay. Each geode robot costs 2 ore and 13 obsidian.
|
||||
Blueprint 13: 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 2 ore and 13 obsidian.
|
||||
Blueprint 14: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 18 clay. Each geode robot costs 4 ore and 16 obsidian.
|
||||
Blueprint 15: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 5 clay. Each geode robot costs 3 ore and 15 obsidian.
|
||||
Blueprint 16: 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 17: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 7 clay. Each geode robot costs 2 ore and 9 obsidian.
|
||||
Blueprint 18: 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 3 ore and 12 obsidian.
|
||||
Blueprint 19: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 18 clay. Each geode robot costs 3 ore and 8 obsidian.
|
||||
Blueprint 20: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 7 clay. Each geode robot costs 4 ore and 13 obsidian.
|
||||
Blueprint 21: 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 22: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 14 clay. Each geode robot costs 3 ore and 8 obsidian.
|
||||
Blueprint 23: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 15 clay. Each geode robot costs 3 ore and 16 obsidian.
|
||||
Blueprint 24: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 18 clay. Each geode robot costs 3 ore and 13 obsidian.
|
||||
Blueprint 25: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 15 clay. Each geode robot costs 2 ore and 20 obsidian.
|
||||
Blueprint 26: 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 27: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 17 clay. Each geode robot costs 2 ore and 13 obsidian.
|
||||
Blueprint 28: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 15 clay. Each geode robot costs 2 ore and 8 obsidian.
|
||||
Blueprint 29: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 19 clay. Each geode robot costs 4 ore and 12 obsidian.
|
||||
Blueprint 30: 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 2 ore and 16 obsidian.
|
|
@ -0,0 +1,11 @@
|
|||
Blueprint 1:
|
||||
Each ore robot costs 4 ore.
|
||||
Each clay robot costs 2 ore.
|
||||
Each obsidian robot costs 3 ore and 14 clay.
|
||||
Each geode robot costs 2 ore and 7 obsidian.
|
||||
|
||||
Blueprint 2:
|
||||
Each ore robot costs 2 ore.
|
||||
Each clay robot costs 3 ore.
|
||||
Each obsidian robot costs 3 ore and 8 clay.
|
||||
Each geode robot costs 3 ore and 12 obsidian.
|
|
@ -0,0 +1,116 @@
|
|||
|
||||
import re
|
||||
sample = {
|
||||
1:{
|
||||
'ore': [4, 0, 0, 0],
|
||||
'clay': [2, 0, 0, 0],
|
||||
'obsidian': [3, 14, 0, 0],
|
||||
'geode': [2, 0, 7, 0],
|
||||
},
|
||||
2:{
|
||||
'ore': [2, 0, 0, 0],
|
||||
'clay': [3, 0, 0, 0],
|
||||
'obsidian': [3, 8, 0, 0],
|
||||
'geode': [3, 0, 12, 0],
|
||||
}}
|
||||
|
||||
robot_number = {'ore': 0, 'clay': 1, 'obsidian': 2, 'geode': 3, 'nothing': 99}
|
||||
|
||||
def parse(line):
|
||||
line = re.sub(r'[^\d]+', ' ', line)
|
||||
idx, ore1, ore2, ore3, clay3, ore4, obs4 = map(int, line.split())
|
||||
return idx, {
|
||||
'ore': [ore1, 0,0,0],
|
||||
'clay': [ore2, 0,0,0],
|
||||
'obsidian': [ore3,clay3,0,0],
|
||||
'geode': [ore4,0,obs4,0],
|
||||
}
|
||||
|
||||
def simulate(blueprint):
|
||||
B = blueprint
|
||||
resources = [0]*4
|
||||
robots = [1,0,0,0]
|
||||
|
||||
rmax = [max(x[i] for x in B.values()) for i in range(3)]
|
||||
rmax.append(99)
|
||||
|
||||
B['nothing'] = [0,0,0,0]
|
||||
|
||||
worth = {}
|
||||
worth['ore'] = 1
|
||||
worth['clay'] = worth['ore']*B['clay'][0]
|
||||
worth['obsidian'] = worth['ore']*B['obsidian'][0] + worth['clay']*B['obsidian'][1]
|
||||
worth['geode'] = worth['ore']*B['geode'][0] + worth['obsidian']*B['geode'][2]
|
||||
|
||||
print(worth)
|
||||
|
||||
|
||||
minutes = 24
|
||||
q = [(0, robots, resources)]
|
||||
del resources
|
||||
del robots
|
||||
for _ in range(minutes):
|
||||
next = []
|
||||
seen = set()
|
||||
for _, robots, resources in q:
|
||||
for robot, cost in B.items():
|
||||
i = robot_number[robot]
|
||||
if robot != 'nothing' and robots[i] >= rmax[i]:
|
||||
continue
|
||||
if not all(x >= y for x, y in zip(resources, cost)):
|
||||
continue
|
||||
|
||||
new = []
|
||||
for x,y,z,m in zip(resources, robots, cost, rmax):
|
||||
x = x+y-z
|
||||
new.append(x)
|
||||
if robot != 'nothing':
|
||||
new_robots = list(robots)
|
||||
new_robots[i] += 1
|
||||
else:
|
||||
new_robots = robots
|
||||
key = str(new_robots)+str(new)
|
||||
if key not in seen:
|
||||
#x = (new[3], new_robots[3], new[2] + new[0], new_robots[2] + new_robots[0], new[1]+new[0], new_robots[1]+new_robots[0], new, new_robots)
|
||||
w = sum(worth[r]*robots[robot_number[r]] for r in worth)
|
||||
x = tuple(reversed(new+new_robots+[new[3]]))
|
||||
#x = (new[3], new_robots)
|
||||
next.append((x, new_robots, new))
|
||||
|
||||
bucket = {}
|
||||
for x,rob,res in next:
|
||||
bucket.setdefault(x[0],[]).append((x,rob,res))
|
||||
|
||||
q = []
|
||||
for i in bucket:
|
||||
bucket[i].sort(reverse=True)
|
||||
q.extend(bucket[i][:2000])
|
||||
|
||||
bucket.clear()
|
||||
|
||||
print(len(q), q[:1])
|
||||
|
||||
print(q[0])
|
||||
return q[0][2][3]
|
||||
|
||||
#simulate(blueprints[1])
|
||||
|
||||
input = {}
|
||||
with open('input') as f:
|
||||
for line in f:
|
||||
idx, bp = parse(line)
|
||||
input[idx] = bp
|
||||
|
||||
def solve(input):
|
||||
t = 0
|
||||
for idx, B in input.items():
|
||||
g = simulate(B)
|
||||
t += idx*g
|
||||
print(idx, g)
|
||||
print("---")
|
||||
print(t)
|
||||
return t
|
||||
|
||||
assert solve(sample) == 33
|
||||
solve(input)
|
||||
|
Loading…
Reference in New Issue