diff options
Diffstat (limited to '2_2023.py')
-rw-r--r-- | 2_2023.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/2_2023.py b/2_2023.py new file mode 100644 index 0000000..189d15a --- /dev/null +++ b/2_2023.py @@ -0,0 +1,25 @@ +import sys +from collections import defaultdict + +D = open(sys.argv[1]).read().strip() +p1 = 0 +p2 = 0 +for line in D.split("\n"): + ok = True + id_, line = line.split(":") + V = defaultdict(int) + for event in line.split(";"): + for balls in event.split(","): + n, colour = balls.split() + n = int(n) + V[colour] = max(V[colour], n) + if int(n) > {"red": 12, "green": 13, "blue": 14}.get(colour, 0): + ok = False + score = 1 + for v in V.values(): + score *= v + p2 += score + if ok: + p1 += int(id_.split()[-1]) +print(p1) +print(p2) |