day 15 python part 2
parent
af21ad12cc
commit
5f76b4e69d
35
day15/sol.py
35
day15/sol.py
|
@ -15,10 +15,35 @@ for sx,sy,bx,by in data:
|
|||
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)
|
||||
#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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue