02-2 fertig

This commit is contained in:
2023-12-02 12:40:25 +01:00
parent b0015c71e9
commit 7a1466a9c4

View File

@@ -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()