Skip to content

Commit

Permalink
[2022][day 19] add part 2 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
IAjimi committed Dec 19, 2022
1 parent ab3b186 commit 9ba4b01
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
26 changes: 19 additions & 7 deletions 2022/AOC19.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import functools
import parse
from collections import defaultdict
from typing import List, Tuple, Set

from _utils import read_input, timer, Solution
Expand All @@ -15,8 +17,8 @@ def process_input(filename: str):

@functools.lru_cache(maxsize=None)
def collect_geodes(
t: int, ore_robot: int, clay_robot: int, obs_robot: int, geode_robot: int, ore: int, clay: int, obisidian: int, geode: int, blueprint
) -> int:
t, ore_robot, clay_robot, obs_robot, geode_robot, ore, clay, obisidian, geode, blueprint
):
if t <= 0:
return geode

Expand Down Expand Up @@ -67,7 +69,7 @@ def collect_geodes(
)

# build new ore robot
if blueprint[0][0] <= ore:
if blueprint[0][0] <= ore and ore_robot < max_ore_spend:
options.append(
collect_geodes(
t - 1,
Expand All @@ -84,7 +86,7 @@ def collect_geodes(
)

# build new clay robot
if blueprint[1][0] <= ore:
if blueprint[1][0] <= ore and clay_robot < max_clay_spend:
options.append(
collect_geodes(
t - 1,
Expand All @@ -104,6 +106,7 @@ def collect_geodes(
if (
blueprint[2][0] <= ore
and blueprint[2][1] <= clay
and obs_robot < max_obs_spend
):
options.append(
collect_geodes(
Expand All @@ -123,20 +126,29 @@ def collect_geodes(
return max(options)


def part1(blueprints) -> int:
# 43 seconds for 2 blueprints.. -> expected to run for 10 min
def part1(blueprints):
quality_levels = []
for i, bp in enumerate(blueprints, start=1):
geodes = collect_geodes(24, 1, 0, 0, 0, 0, 0, 0, 0, bp)
print(f"max geodes collected with blueprint {i} are {geodes}")
quality_levels.append((i)*geodes)
return sum(quality_levels)


def part2(blueprints):
all_geodes = []
print(f"{datetime.datetime.now()} - start")
for i, bp in enumerate(blueprints, start=1):
geodes = collect_geodes(32, 1, 0, 0, 0, 0, 0, 0, 0, bp)
print(f"{datetime.datetime.now()} - max geodes collected with blueprint {i} are {geodes}")
all_geodes.append(geodes)
return sum(all_geodes)

@timer
def main(filename: str) -> Solution:
blueprints = process_input(filename)
part_1_solution = part1(blueprints)
part_2_solution = 0
part_2_solution = part2(blueprints)
return part_1_solution, part_2_solution


Expand Down
30 changes: 30 additions & 0 deletions 2022/aoc19.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Blueprint 1: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 16 clay. Each geode robot costs 3 ore and 20 obsidian.
Blueprint 2: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 20 clay. Each geode robot costs 2 ore and 15 obsidian.
Blueprint 3: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 15 clay. Each geode robot costs 3 ore and 8 obsidian.
Blueprint 4: 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 5: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 12 clay. Each geode robot costs 3 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 2 ore and 16 obsidian.
Blueprint 7: 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 8: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 11 clay. Each geode robot costs 2 ore and 10 obsidian.
Blueprint 9: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 16 clay. Each geode robot costs 3 ore and 9 obsidian.
Blueprint 10: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 2 ore and 16 clay. Each geode robot costs 2 ore and 8 obsidian.
Blueprint 11: 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 3 ore and 12 obsidian.
Blueprint 12: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 7 clay. Each geode robot costs 4 ore and 20 obsidian.
Blueprint 13: 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 14: 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 8 obsidian.
Blueprint 15: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 10 clay. Each geode robot costs 2 ore and 7 obsidian.
Blueprint 16: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 9 clay. Each geode robot costs 2 ore and 20 obsidian.
Blueprint 17: 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 18: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 16 clay. Each geode robot costs 4 ore and 16 obsidian.
Blueprint 19: 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 20: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 14 clay. Each geode robot costs 3 ore and 17 obsidian.
Blueprint 21: 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 19 obsidian.
Blueprint 22: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 7 clay. Each geode robot costs 2 ore and 16 obsidian.
Blueprint 23: 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 24: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 20 clay. Each geode robot costs 2 ore and 20 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 5 clay. Each geode robot costs 3 ore and 18 obsidian.
Blueprint 27: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 19 clay. Each geode robot costs 2 ore and 12 obsidian.
Blueprint 28: 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 29: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 6 clay. Each geode robot costs 2 ore and 10 obsidian.
Blueprint 30: 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 3 ore and 9 obsidian.

0 comments on commit 9ba4b01

Please sign in to comment.