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 2025/12

+34
+34
2025/day12.py
··· 1 + import fileinput 2 + from collections import Counter 3 + 4 + 5 + BLOCK_SIZES = Counter() 6 + 7 + part_1 = 0 8 + curr_block = None 9 + 10 + for line in fileinput.input(): 11 + line = line.strip() 12 + 13 + # Reading a region. 14 + if 'x' in line: 15 + size, counts = line.split(': ') 16 + w, h = [int(x) for x in size.split('x')] 17 + counts = [int(x) for x in counts.split()] 18 + 19 + region_area = w * h 20 + block_area = sum(BLOCK_SIZES[i] * n for i, n in enumerate(counts)) 21 + 22 + # The puzzle input is constructed to nicely tessellate the rectangular 23 + # grid, so all we need to do is check if the area amount would work. 24 + if block_area <= region_area: 25 + ans += part_1 26 + 27 + else: 28 + if ':' in line: 29 + curr_block = int(line[:-1]) 30 + elif '#' in line or '.' in line: 31 + BLOCK_SIZES[curr_block] += line.count('#') 32 + 33 + print("Part 1:", part_1) 34 +