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.

at main 34 lines 868 B view raw
1import fileinput 2from collections import Counter 3 4 5BLOCK_SIZES = Counter() 6 7part_1 = 0 8curr_block = None 9 10for 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 33print("Part 1:", part_1) 34