02-2 fertig
This commit is contained in:
29
02/02-2.py
29
02/02-2.py
@@ -1,33 +1,26 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
RED = 12
|
power_sum = 0
|
||||||
GREEN = 13
|
|
||||||
BLUE = 14
|
|
||||||
|
|
||||||
id_sum = 0
|
|
||||||
|
|
||||||
input_file = open("input.txt", "r")
|
input_file = open("input.txt", "r")
|
||||||
|
|
||||||
for line in input_file:
|
for line in input_file:
|
||||||
possible = True
|
|
||||||
line = line.replace("Game ", "").strip()
|
line = line.replace("Game ", "").strip()
|
||||||
line = line.split(":")
|
games = line.split(":")[1].split(";")
|
||||||
game_id = int(line[0])
|
red_max, green_max, blue_max = 1, 1, 1
|
||||||
games = line[1].split(";")
|
|
||||||
for game in games:
|
for game in games:
|
||||||
game = game.split(",")
|
game = game.split(",")
|
||||||
for grab in game:
|
for grab in game:
|
||||||
grab = grab.split()
|
grab = grab.split()
|
||||||
if grab[1] == "red" and int(grab[0]) > RED:
|
if grab[1] == "red" and int(grab[0]) > red_max:
|
||||||
possible = False
|
red_max = int(grab[0])
|
||||||
if grab[1] == "green" and int(grab[0]) > GREEN:
|
if grab[1] == "green" and int(grab[0]) > green_max:
|
||||||
possible = False
|
green_max = int(grab[0])
|
||||||
if grab[1] == "blue" and int(grab[0]) > BLUE:
|
if grab[1] == "blue" and int(grab[0]) > blue_max:
|
||||||
possible = False
|
blue_max = int(grab[0])
|
||||||
if possible:
|
power_sum += red_max * green_max * blue_max
|
||||||
id_sum += game_id
|
|
||||||
|
|
||||||
print(id_sum)
|
print(power_sum)
|
||||||
|
|
||||||
input_file.close()
|
input_file.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user