summaryrefslogtreecommitdiffstats
path: root/prog/aoc/23/2/1.py
blob: db1ec3a8aed6b98c3ee47e86996151fbb6c6d30e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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)