#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)))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: AoC Day 3: No Matter How You Slice It
For further actions, you may consider blocking this person and/or reporting abuse