From 7a1466a9c46922d93c89f66882b9fe82c34d8534 Mon Sep 17 00:00:00 2001 From: tebarius Date: Sat, 2 Dec 2023 12:40:25 +0100 Subject: [PATCH] 02-2 fertig --- 02/02-2.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/02/02-2.py b/02/02-2.py index 17942d1..12b9c6e 100644 --- a/02/02-2.py +++ b/02/02-2.py @@ -1,33 +1,26 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -RED = 12 -GREEN = 13 -BLUE = 14 - -id_sum = 0 +power_sum = 0 input_file = open("input.txt", "r") for line in input_file: - possible = True line = line.replace("Game ", "").strip() - line = line.split(":") - game_id = int(line[0]) - games = line[1].split(";") + games = line.split(":")[1].split(";") + red_max, green_max, blue_max = 1, 1, 1 for game in games: game = game.split(",") for grab in game: grab = grab.split() - if grab[1] == "red" and int(grab[0]) > RED: - possible = False - if grab[1] == "green" and int(grab[0]) > GREEN: - possible = False - if grab[1] == "blue" and int(grab[0]) > BLUE: - possible = False - if possible: - id_sum += game_id + if grab[1] == "red" and int(grab[0]) > red_max: + red_max = int(grab[0]) + if grab[1] == "green" and int(grab[0]) > green_max: + green_max = int(grab[0]) + if grab[1] == "blue" and int(grab[0]) > blue_max: + blue_max = int(grab[0]) + power_sum += red_max * green_max * blue_max -print(id_sum) +print(power_sum) input_file.close()