This commit is contained in:
Tyrel Souza 2022-12-19 01:10:23 -05:00
parent d40c2fec64
commit 2392cf3e57
1 changed files with 44 additions and 48 deletions

View File

@ -5,30 +5,6 @@ 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:
@ -38,9 +14,33 @@ def load_blueprints(rows):
"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
blueprints[bp.id] = bp
return blueprints
@dataclass
class Blueprint():
id :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 can_produce_ore_robot(self, r):
return r.ore >= self.ore_cost
def can_produce_clay_robot(self, r):
return r.ore >= self.clay_ore_cost
def can_produce_obsidian_robot(self, r):
return r.ore >= self.obsidian_ore_cost and r.clay >= self.obsidian_clay_cost
def can_produce_geode_robot(self, r):
return r.ore >= self.geode_ore_cost and r.obsidian >= self.geode_obsidian_cost
@dataclass
class Resources():
ore: int = 0
@ -48,6 +48,7 @@ class Resources():
obsidian: int = 0
geodes: int = 0
@dataclass
class Robots():
ore: int = 1
@ -60,11 +61,11 @@ class Robots():
#def part1(rows, minutes=12):
def part1(rows, minutes=24):
blueprints = load_blueprints(rows)
quality = 0
for _,bp in blueprints.items():
resources = Resources()
robots = Robots()
print(robots)
for minute in range(1, minutes+1):
print(f"== Minute {minute} ==")
@ -75,13 +76,14 @@ def part1(rows, minutes=24):
# 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.can_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
if bp.produce_obsidian_robot(resources):
if bp.can_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.")
@ -89,12 +91,12 @@ def part1(rows, minutes=24):
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
if bp.can_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
# GATHER RESOURCES
resources.ore += robots.ore
@ -123,18 +125,12 @@ def part1(rows, minutes=24):
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.")
robots.geodes += 1
print(f"The new geode-cracking robot is ready; you now have {robots.geodes} of them.")
print()
print(geodes)
break
quality += (bp.id * resources.geodes)
print(quality)