2023 - Day 2 part 2
This commit is contained in:
parent
08c67239f1
commit
1c0e91b4ba
1 changed files with 32 additions and 0 deletions
32
2023/2/2_2.py
Normal file
32
2023/2/2_2.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# 2023 - Advent Of Code 2 - part 2
|
||||||
|
|
||||||
|
# file = 'input_example.txt'
|
||||||
|
file = 'input.txt'
|
||||||
|
|
||||||
|
maxb = {'red': 12, 'green': 13, 'blue': 14}
|
||||||
|
|
||||||
|
# pylint: disable=consider-using-with
|
||||||
|
input_lines = [line.strip('\n') for line in open(file, encoding="utf-8")]
|
||||||
|
accum = 0
|
||||||
|
for line in input_lines:
|
||||||
|
impossible = False
|
||||||
|
games_list = line.split(':')
|
||||||
|
game_num = int(games_list[0][4:])
|
||||||
|
# print(f"{game_num}")
|
||||||
|
colors = {'red': 0, 'green': 0, 'blue': 0}
|
||||||
|
for game in games_list[1].split(';'):
|
||||||
|
for ball in game.split(','):
|
||||||
|
(space, num, color) = ball.split(' ')
|
||||||
|
# print(f'{num} {color}')
|
||||||
|
if int(num) > colors[color]:
|
||||||
|
colors[color] = int(num)
|
||||||
|
|
||||||
|
power = 1
|
||||||
|
# pylint: disable=consider-using-dict-items
|
||||||
|
for c in colors:
|
||||||
|
power *= colors[c]
|
||||||
|
print(f'game {game_num} power: {power}')
|
||||||
|
accum += power
|
||||||
|
|
||||||
|
print(f"sum: {accum}")
|
Loading…
Reference in a new issue