day 15 python part 2

main
magical 2022-12-14 22:47:37 -08:00
parent af21ad12cc
commit 5f76b4e69d
1 changed files with 30 additions and 5 deletions

View File

@ -15,10 +15,35 @@ for sx,sy,bx,by in data:
dy = abs(sy-by) dy = abs(sy-by)
dist = dx+dy dist = dx+dy
y = Y-sy y = Y-sy
for x in range(-dist,dist+1): #for x in range(-dist,dist+1):
if abs(x)+abs(y) <= dist: # if abs(x)+abs(y) <= dist:
p = (sx+x, sy+y) # p = (sx+x, sy+y)
if p != (bx,by): # if p != (bx,by):
none.add(sx+x) # none.add(sx+x)
print(len(none)) 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)