27 lines
758 B
Python
27 lines
758 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
power_sum = 0
|
|
|
|
input_file = open("input.txt", "r")
|
|
|
|
for line in input_file:
|
|
line = line.replace("Game ", "").strip()
|
|
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_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(power_sum)
|
|
|
|
input_file.close()
|