diff --git a/2022/full/day19.txt b/2022/full/day19.txt index e69de29..e5a5cad 100644 --- a/2022/full/day19.txt +++ b/2022/full/day19.txt @@ -0,0 +1,30 @@ +Blueprint 1: 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 11 obsidian. +Blueprint 2: 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 3: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 4 ore and 8 obsidian. +Blueprint 4: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 10 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 4 ore and 5 clay. Each geode robot costs 3 ore and 7 obsidian. +Blueprint 6: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 11 clay. Each geode robot costs 4 ore and 12 obsidian. +Blueprint 7: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 16 clay. Each geode robot costs 3 ore and 15 obsidian. +Blueprint 8: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 19 clay. Each geode robot costs 4 ore and 7 obsidian. +Blueprint 9: 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 10: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 4 ore and 15 obsidian. +Blueprint 11: 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 12: 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 13: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 17 clay. Each geode robot costs 3 ore and 11 obsidian. +Blueprint 14: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 12 clay. Each geode robot costs 3 ore and 17 obsidian. +Blueprint 15: 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 16: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 11 clay. Each geode robot costs 3 ore and 15 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 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 8 clay. Each geode robot costs 3 ore and 7 obsidian. +Blueprint 19: 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 20: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 17 clay. Each geode robot costs 4 ore and 16 obsidian. +Blueprint 21: Each ore robot costs 2 ore. Each clay robot costs 2 ore. Each obsidian robot costs 2 ore and 20 clay. Each geode robot costs 2 ore and 14 obsidian. +Blueprint 22: 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 23: 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 13 obsidian. +Blueprint 24: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 20 clay. Each geode robot costs 3 ore and 9 obsidian. +Blueprint 25: 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 3 ore and 20 obsidian. +Blueprint 26: 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 27: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 13 clay. Each geode robot costs 3 ore and 12 obsidian. +Blueprint 28: 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 29: Each ore robot costs 2 ore. Each clay robot costs 2 ore. Each obsidian robot costs 2 ore and 10 clay. Each geode robot costs 2 ore and 11 obsidian. +Blueprint 30: 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. diff --git a/2022/python/day19.py b/2022/python/day19.py index c385afd..74ec95e 100644 --- a/2022/python/day19.py +++ b/2022/python/day19.py @@ -1,15 +1,145 @@ import matrix import shared -import itertools -import functools +from pprint import pprint +from dataclasses import dataclass +from scanf import scanf + + + +@dataclass +class Blueprint(): + blueprint:int + ore_ore_cost: int + clay_ore_cost: int + obsidian_ore_cost: int + obsidian_clay_cost: int + geode_ore_cost: int + geode_obsidian_cost: int + + def produce_ore_robot(self, r): + return r.ore >= self.ore_cost + + def produce_clay_robot(self, r): + return r.ore >= self.clay_ore_cost + + def produce_obsidian_robot(self, r): + return r.ore >= self.obsidian_ore_cost and r.clay >= self.obsidian_clay_cost + + def produce_geode_robot(self, r): + return r.ore >= self.geode_ore_cost and r.obsidian >= self.geode_obsidian_cost + + +def load_blueprints(rows): + blueprints = {} + for row in rows: + b, o_c, c_c, o_o_c, o_c_c, g_o_c, g_o_c = scanf( + "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", row) + bp = Blueprint(b, o_c, c_c, o_o_c, o_c_c, g_o_c, g_o_c) + blueprints[bp.blueprint] = bp + return blueprints + +@dataclass +class Resources(): + ore: int = 0 + clay: int = 0 + obsidian: int = 0 + geodes: int = 0 + +@dataclass +class Robots(): + ore: int = 1 + clay: int = 0 + obsidian: int = 0 + geodes: int = 0 + # @shared.profile -def part1(rows): - pass +#def part1(rows, minutes=12): +def part1(rows, minutes=24): + blueprints = load_blueprints(rows) + + for _,bp in blueprints.items(): + resources = Resources() + robots = Robots() + print(robots) + for minute in range(1, minutes+1): + print(f"== Minute {minute} ==") + + _add_ore = False + _add_clay = False + _add_obsidian = False + _add_geode = False + + + # SPEND THE RESOURCES + if bp.produce_geode_robot(resources): + print(f"Spend {bp.geode_ore_cost} ore and {bp.geode_obsidian_cost} obsidian to start building a geode-cracking robot.") + resources.ore -= bp.geode_ore_cost + resources.obsidian -= bp.geode_obsidian_cost + _add_geode = True + + if bp.produce_obsidian_robot(resources): + # Do we have enough to build geodes? + if robots.obsidian < bp.geode_obsidian_cost: + print(f"Spend {bp.obsidian_ore_cost} ore and {bp.obsidian_clay_cost} clay to start building an obsidian-collecting robot.") + resources.ore -= bp.obsidian_ore_cost + resources.clay -= bp.obsidian_clay_cost + _add_obsidian = True + + if bp.produce_clay_robot(resources): + # Do we have enough to build obsidian? + if robots.clay < bp.obsidian_ore_cost: + print(f"Spend {bp.clay_ore_cost} ore to start building a clay-collecting robot.") + resources.ore -= bp.clay_ore_cost + _add_clay = True + + # GATHER RESOURCES + resources.ore += robots.ore + resources.clay += robots.clay + resources.obsidian += robots.obsidian + resources.geodes += robots.geodes + + if robots.ore > 0: + print(f"{robots.ore} ore-collecting robot collects {robots.ore} ore; you now have {resources.ore} ore.") + if robots.clay > 0: + print(f"{robots.clay} clay-collecting robot collects {robots.clay} clay; you now have {resources.clay} clay.") + if robots.obsidian > 0: + print(f"{robots.obsidian} obsidian-collecting robot collects {robots.obsidian} obsidian; you now have {resources.obsidian} obsidian.") + if robots.geodes > 0: + print(f"{robots.geodes} geode-cracking robot collects {robots.geodes} geodes; you now have {resources.geodes} geodes.") + + + # PRODUCE ROBOTS + if _add_ore: + robots.ore += 1 + print(f"The new ore-collecting robot is ready; you now have {robots.ore} of them.") + if _add_clay: + robots.clay += 1 + print(f"The new clay-collecting robot is ready; you now have {robots.clay} of them.") + if _add_obsidian: + robots.obsidian += 1 + print(f"The new obsidian-collecting robot is ready; you now have {robots.obsidian} of them.") + if _add_geode: + robots.geode += 1 + print(f"The new geode-cracking robot is ready; you now have {robots.geode} of them.") + + print() + print(geodes) + break + + + + + + + # @shared.profile -def part2(rows): +def part2(rows, minutes=24): pass diff --git a/2022/samples/day19.txt b/2022/samples/day19.txt index e69de29..f39c094 100644 --- a/2022/samples/day19.txt +++ b/2022/samples/day19.txt @@ -0,0 +1,2 @@ +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.