Day 2 part 2
This commit is contained in:
parent
d1b8c279de
commit
548a009d30
19
d02/main.py
19
d02/main.py
@ -58,6 +58,25 @@ def part1(input: Path) -> int:
|
|||||||
return total
|
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__":
|
if __name__ == "__main__":
|
||||||
answer1 = part1(Path("./input.txt"))
|
answer1 = part1(Path("./input.txt"))
|
||||||
print("part 1", answer1)
|
print("part 1", answer1)
|
||||||
|
answer2 = part2(Path("./input.txt"))
|
||||||
|
print("part 2", answer2)
|
||||||
|
Loading…
Reference in New Issue
Block a user