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 24 lines 658 B view raw
1import fileinput 2from collections import Counter, defaultdict 3 4from utils import parse_line 5 6SQUARES = Counter() 7CLAIMS = defaultdict(list) 8 9for i, line in enumerate(fileinput.input()): 10 _id, x, y, w, h = parse_line(r'#(\d+) @ (\d+),(\d+): (\d+)x(\d+)', line) 11 12 for i in range(x, x + w): 13 for j in range(y, y + h): 14 SQUARES[(i, j)] += 1 15 CLAIMS[_id].append((i, j)) 16 17print "Square inches of fabric within multiple claims:", sum(n > 1 for c, n in SQUARES.items()) 18 19for _id in CLAIMS: 20 for pos in CLAIMS[_id]: 21 if SQUARES[pos] != 1: 22 break 23 else: 24 print "ID of only non-overlapping claim:", _id