day 03
no matter how you slice it
approach
the fabric is a plain 1000 × 1000 list of lists. part 1 adds 1 to every cell each claim covers, then counts the cells above 1.
part 2 paints each claim's id into the grid instead. when a claim lands on a cell that already holds an id, both ids go into an overlaps set; at the end every id from 1 to 1349 that isn't in the set is printed. the comment above it notes it "looks inefficient", and a first wrong attempt is left commented out.
neither part is called at the bottom of the file, and both write to the same global grid (with the axes swapped between them), so they're meant to be run one at a time.
the trick
store claim ids in the cells, so any collision names both claims that overlap.
python
def part2():
overlaps=set()
for st in map(lambda x:x.split(":"),strs):
iden=int(st[0])
pad=list(map(int,st[1].split(",")))
wh=list(map(int,st[2].split("x")))
for i in range(wh[0]):
for j in range(wh[1]):
if grid[pad[1]+j][pad[0]+i]!=0:
overlaps.add(iden)
overlaps.add(grid[pad[1]+j][pad[0]+i])
grid[pad[1]+j][pad[0]+i]=iden
for i in range(1,1350):
if not(i in overlaps):
print(i)