From 1c0e91b4ba717957daa7782870c832df361f7f68 Mon Sep 17 00:00:00 2001 From: kleph Date: Sat, 2 Dec 2023 16:02:27 +0100 Subject: [PATCH] 2023 - Day 2 part 2 --- 2023/2/2_2.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 2023/2/2_2.py diff --git a/2023/2/2_2.py b/2023/2/2_2.py new file mode 100644 index 0000000..4f7c1fd --- /dev/null +++ b/2023/2/2_2.py @@ -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}")