You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
797 B
25 lines
797 B
#!/usr/bin/env python3
|
|
|
|
import sys, re
|
|
|
|
|
|
if __name__ == '__main__':
|
|
games = [line.strip('\n') for line in open(sys.argv[1])]
|
|
|
|
# first: only 12 red cubes, 13 green cubes, and 14 blue cubes
|
|
|
|
res1, res2 = 0, 0
|
|
for l in games:
|
|
num = re.compile(r"Game (?P<num>\d+):").search(l).group('num')
|
|
pred = max(int(r) for r in re.compile(r"(\d+) red").findall(l))
|
|
pgreen = max(int(g) for g in re.compile(r"(\d+) green").findall(l))
|
|
pblue = max(int(b) for b in re.compile(r"(\d+) blue").findall(l))
|
|
# challenge 1
|
|
if not (pred > 12 or pgreen > 13 or pblue > 14): res1 += int(num)
|
|
# challenge 2
|
|
res2 += pred * pgreen * pblue
|
|
|
|
print("challenge 1:" + "\n" + str(res1) + "\n")
|
|
|
|
print("challenge 2:" + "\n" + str(res2) + "\n")
|
|
|
|
|