day 2 part 2
parent
70a7f578cb
commit
771e4ec0c4
13
day02/sol.py
13
day02/sol.py
|
@ -1,12 +1,19 @@
|
||||||
import sys
|
import sys
|
||||||
|
def product(items):
|
||||||
|
t = 1
|
||||||
|
for x in items:
|
||||||
|
t *= x
|
||||||
|
return t
|
||||||
input = sys.stdin
|
input = sys.stdin
|
||||||
total = 0
|
total = 0
|
||||||
|
power = 0
|
||||||
game_num = 0
|
game_num = 0
|
||||||
for line in input:
|
for line in input:
|
||||||
game, _, data = line.partition(": ")
|
game, _, data = line.partition(": ")
|
||||||
game_num += 1
|
game_num += 1
|
||||||
takes = data.split(";")
|
takes = data.split(";")
|
||||||
possible = True
|
possible = True
|
||||||
|
minset = {'green':0, 'blue':0, 'red':0}
|
||||||
for t in takes:
|
for t in takes:
|
||||||
cubes = t.split(",")
|
cubes = t.split(",")
|
||||||
cubes = [x.split() for x in t.split(",")]
|
cubes = [x.split() for x in t.split(",")]
|
||||||
|
@ -15,7 +22,13 @@ for line in input:
|
||||||
cubes.get('green', 0) <= 13 and \
|
cubes.get('green', 0) <= 13 and \
|
||||||
cubes.get('blue', 0) <= 14 and \
|
cubes.get('blue', 0) <= 14 and \
|
||||||
cubes.get("red", 0) <= 12
|
cubes.get("red", 0) <= 12
|
||||||
|
for color, n in cubes.items():
|
||||||
|
minset[color] = max(minset[color], n)
|
||||||
|
|
||||||
if possible:
|
if possible:
|
||||||
total += game_num
|
total += game_num
|
||||||
|
power += product(minset.values())
|
||||||
|
|
||||||
|
|
||||||
print(total)
|
print(total)
|
||||||
|
print(power)
|
||||||
|
|
Loading…
Reference in New Issue