blob: db1ec3a8aed6b98c3ee47e86996151fbb6c6d30e (
plain) (
tree)
|
|
#!/usr/bin/python3
def game_parser(line):
index = int(line.split(": ")[0].split(" ")[1])
pullouts = []
maxr = 0
maxg = 0
maxb = 0
for pullout in line.split(": ")[1].split("; "):
colordict = {}
for color in pullout.split(", "):
colordict[color.split(" ")[1]] = int(color.split(" ")[0])
r = 0
g = 0
b = 0
if "red" in colordict.keys():
r = colordict["red"]
if colordict["red"] > maxr:
maxr = colordict["red"]
if "green" in colordict.keys():
g = colordict["green"]
if colordict["green"] > maxg:
maxg = colordict["green"]
if "blue" in colordict.keys():
b = colordict["blue"]
if colordict["blue"] > maxb:
maxb = colordict["blue"]
pullouts.append((r, g, b))
return (index, (maxr, maxg, maxb), pullouts)
sumindexes = 0
sumpowers = 0
try:
while True:
game = game_parser(input())
if game[1][0] <= 12 and game[1][1] <= 13 and game[1][2] <= 14:
sumindexes += game[0]
sumpowers += game[1][0] * game[1][1] * game[1][2]
except EOFError:
print("1: " , sumindexes)
print("2: " , sumpowers)
|