data = [] for line in open("input"): words = line.replace(":", "").replace(",","").split() coords = [int(w[w.index('=')+1:]) for w in words if '=' in w] data.append(coords) #print(data) none = set() Y = 10 Y = 2000000 for sx,sy,bx,by in data: dx = abs(sx-bx) dy = abs(sy-by) dist = dx+dy y = Y-sy #for x in range(-dist,dist+1): # if abs(x)+abs(y) <= dist: # p = (sx+x, sy+y) # if p != (bx,by): # none.add(sx+x) print(len(none)) # find the closest sensor to x,y within dist def mindist(x,y): for sx,sy,bx,by in data: dx = abs(sx-bx) dy = abs(sy-by) dist = dx+dy dx = abs(x-sx) dy = abs(y-sy) d2 = dx+dy if d2 <= dist: yield dist-d2 for y in range(0, 4000000+1): x = 0 while x <= 4000000: for d in mindist(x,y): x += d+1 break else: print(x,y) break if y % 10000 == 0: print(y)