re: AoC Day 3: No Matter How You Slice It VIEW POST

FULL DISCUSSION
 

#Part 1

from collections import defaultdict
claims = defaultdict(list)
i = 1
for line in film.split('\n'):
    if line is None or line == '':
        continue
    _, _, offset, size = line.split(' ')

    l, t = map(int, offset[:-1].split(','))
    w, h = map(int, size.split('x'))

    claims.update({(l+x,t+y): claims.get((l+x,t+y),[]) + [i] for x in range(1,w+1) for y in range(1,h+1)})
    i += 1
print(len([claim for claim in claims.values() if len(claim) > 1]))

#Part 2
overlapping_claims = []
for x in claims.values():
    if len(x) > 1:
        overlapping_claims += x
print(set(range(1,1360)).difference(set(overlapping_claims)))
code of conduct - report abuse