From 548a009d302be4160bcd3d70da8fa2ffdcd9b26d Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Sat, 2 Dec 2023 14:11:25 -0800 Subject: [PATCH] Day 2 part 2 --- d02/main.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/d02/main.py b/d02/main.py index 576528d..ffc5591 100644 --- a/d02/main.py +++ b/d02/main.py @@ -58,6 +58,25 @@ def part1(input: Path) -> int: return total +def part2(input: Path) -> int: + total = 0 + with input.open() as f: + for line in f: + bag = Grab(red=0, blue=0, green=0) + game = parse_line(line) + power = 1 + for color in bag: + bag[color] = max(grab[color] for grab in game.grabs) + power *= bag[color] + + # print(bag, power) + total += power + + return total + + if __name__ == "__main__": answer1 = part1(Path("./input.txt")) print("part 1", answer1) + answer2 = part2(Path("./input.txt")) + print("part 2", answer2)