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.

17 lines
464B

  1. import math
  2. import re
  3. text = open(0).read()
  4. ans1 = 0
  5. ans2 = 0
  6. for idx, line in enumerate(text.splitlines(), 1):
  7. parse = lambda string: {v: int(k) for k, v in re.findall(r'(\d+) (r|g|b)', string)}
  8. games = [parse(game) for game in re.findall(r'[^:;]+', line)[1:]]
  9. rgb = [max(game.get(k, 0) for game in games) for k in 'rgb']
  10. ans1 += all(qty <= lim for qty, lim in zip(rgb, [12, 13, 14])) and idx
  11. ans2 += math.prod(rgb)
  12. print(ans1)
  13. print(ans2)