add solution to part b, still not happy

This commit is contained in:
2023-12-02 16:22:12 +01:00
parent 35051f0ef3
commit 325146fe36

View File

@@ -1,6 +1,7 @@
from aocd.models import Puzzle from aocd.models import Puzzle
from aocd import submit from aocd import submit
def valid_games(games: list) -> list: def valid_games(games: list) -> list:
""" """
Solve part a. Solve part a.
@@ -26,6 +27,34 @@ def valid_games(games:list) -> list:
valid_ids.append(i) valid_ids.append(i)
return valid_ids return valid_ids
def minimum_sets(games: list) -> list:
"""
Solve part b.
- figure out the minimum amount of cubes necessary of each color for each throw
- multiply the values of each minimum number together
- to solve sum these powers up
"""
# find all minimas
minimas = []
for i, game in enumerate(games.split("\n"), start=1):
minimum = {"red": 0, "green": 0, "blue": 0}
throws = game.split(":")[1].split(";")
for throw in throws:
cubes = throw.split(",")
for cube in cubes:
_, amount, color = cube.split(" ")
if int(amount) > minimum[color]:
minimum[color] = int(amount)
minimas.append(minimum)
# calculate all powers
powers = []
for minimum in minimas:
powers.append(minimum["red"] * minimum["green"] * minimum["blue"])
return powers
if __name__ == "__main__": if __name__ == "__main__":
# get puzzle and parse data # get puzzle and parse data
puzzle = Puzzle(year=2023, day=2) puzzle = Puzzle(year=2023, day=2)
@@ -36,6 +65,6 @@ if __name__ == "__main__":
submit(answer_a, part="a", day=2, year=2023) submit(answer_a, part="a", day=2, year=2023)
# part b: # part b:
#answer_b = 0 answer_b = sum(minimum_sets(puzzle.input_data))
#print(f"{answer_b}") print(f"{answer_b}")
#submit(answer_b, part="b", day=2, year=2023) submit(answer_b, part="b", day=2, year=2023)