My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2023/02

+36
+36
2023/day02.py
··· 1 + import fileinput 2 + from collections import Counter 3 + 4 + from utils import mul 5 + 6 + PART_1_LIMITS = { 7 + 'red': 12, 8 + 'green': 13, 9 + 'blue': 14, 10 + } 11 + 12 + part_1 = 0 13 + part_2 = 0 14 + 15 + for line in fileinput.input(): 16 + game, log = line.strip().split(': ') 17 + game_id = int(game[5:]) 18 + 19 + part_1_poss = True 20 + part_2_mins = Counter() 21 + 22 + for turn in log.split('; '): 23 + for entry in turn.split(', '): 24 + n, color = entry.split(' ') 25 + n = int(n) 26 + if n > PART_1_LIMITS[color]: 27 + part_1_poss = False 28 + part_2_mins[color] = max(part_2_mins[color], n) 29 + 30 + if part_1_poss: 31 + part_1 += game_id 32 + 33 + part_2 += mul(part_2_mins.values()) 34 + 35 + print("Part 1:", part_1) 36 + print("Part 2:", part_2)