36 lines
915 B
Python
36 lines
915 B
Python
|
import fileinput
|
||
|
from functools import reduce
|
||
|
|
||
|
def main():
|
||
|
part1 = 0
|
||
|
part2 = 0
|
||
|
|
||
|
for i, line in enumerate(fileinput.input()):
|
||
|
line = line.strip()
|
||
|
subsets = line.split(": ")[1].split("; ")
|
||
|
|
||
|
maxes = {}
|
||
|
|
||
|
part1_possible = True
|
||
|
for subset in subsets:
|
||
|
for balls in subset.split(", "):
|
||
|
count, color = balls.split()
|
||
|
count = int(count)
|
||
|
maxes[color] = max(maxes.get(color, 0), count)
|
||
|
part1_possible = (
|
||
|
part1_possible
|
||
|
and (color != "red" or count <= 12)
|
||
|
and (color != "green" or count <= 13)
|
||
|
and (color != "blue" or count <= 14)
|
||
|
)
|
||
|
|
||
|
if part1_possible:
|
||
|
part1 += i + 1
|
||
|
|
||
|
power = reduce(lambda x, y: x * y, maxes.values())
|
||
|
part2 += power
|
||
|
|
||
|
print(part1, part2)
|
||
|
|
||
|
main()
|