AoC/2023/days/02/part2.py

32 lines
712 B
Python
Raw Permalink Normal View History

2024-06-02 17:38:51 +02:00
import numpy as np
with open("data/input.txt", "r") as f:
games = f.read()
limits = {
"red": 12,
"green": 13,
"blue": 14
}
s = 0
for game in games.split("\n")[:-1]:
parts = game.split(":")
head = parts[0]
identifier = head.split(" ")[1]
max_counts = dict(red=0, green=0, blue=0)
for draw in parts[1].split(";"):
draw = draw.strip()
for count in draw.split(","):
count = count.strip()
count_parts = count.split(" ")
color = count_parts[1]
amount = int(count_parts[0])
if amount > max_counts[color]:
max_counts[color] = amount
s += np.prod(list(max_counts.values()))
print(s)