Skip to content

Instantly share code, notes, and snippets.

@nakashkumar
Created December 2, 2023 15:45
Show Gist options
  • Save nakashkumar/867f2cf2c4d1a5a7c23191450b7ec955 to your computer and use it in GitHub Desktop.
Save nakashkumar/867f2cf2c4d1a5a7c23191450b7ec955 to your computer and use it in GitHub Desktop.
import re
part_a_ans = 0
part_b_ans = 0
with open("p2.in", "r") as fi:
for lin in fi:
game_num = int(re.findall("Game (\d+):", lin)[0])
greens = map(int, re.findall('(\d+) green', lin))
reds = map(int, re.findall('(\d+) red', lin))
blues = map(int, re.findall('(\d+) blue', lin))
max_red = max(reds)
max_green = max(greens)
max_blue = max(blues)
if max_red <= 12 and max_green <= 13 and max_blue <= 14:
part_a_ans += game_num
part_b_ans += (max_red * max_green * max_blue)
print(part_a_ans)
print(part_b_ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment