oops, we can't walk diagonally

This commit is contained in:
DUEFON 2022-12-13 00:53:54 +01:00
parent 7e9aa6607d
commit 4f973442e4
1 changed files with 29 additions and 12 deletions

View File

@ -2,24 +2,41 @@
from useful import *
a = np.asarray([[ord(c) for c in l] for l in lines(open(0))])
a = np.arange(9).reshape((3,3)) # todo remove
e = s = 666
#a = np.arange(9).reshape((3,3)) # todo remove
E, S = (0,0), (2,2)
for (y, x), v in np.ndenumerate(a): # bleh
if v == ord('E'):
e = (y, x)
if v == ord('S'):
S = (y, x)
a[y,x] = ord('a')
elif v == ord('S'):
s = (y, x)
elif v == ord('E'):
E = (y, x)
a[y,x] = ord('z')
h, w = a.shape
ic(w,h)
ic(a[18:23,:5])
p = np.pad(a, 1, mode='edge')
comefrom = [[a - p[u:h+u,v:w+v] <= 1 for v in [0,1,2]] for u in [0,1,2]]
goto = [[p[u:h+u,v:w+v] - a <= 1 for v in range(3)] for u in range(3)]
#ic(goto)
s = np.empty((h, w))
s.fill(h*w) # enough
tovisit = deque()
tovisit = deque([S])
def visits(y, x):
return [(u, v) for u in range(y-1,y+2) for v in range(x-1,x+2)
if u >= 0 and u < h and v >= 0 and v < w]
ic(s)
ic(visits(2,2))
return [(y+u-1, x+v-1) for u in range(3) for v in range(3)
if y+u-1 >= 0 and y+u-1 < h and x+v-1 >= 0 and x+v-1 < w
and goto[u][v][y,x]]
#ic(a)
done = False
for i in range(h*w): # still enough
if done: break # gah
ic(tovisit)
ic(s)
lenv = len(tovisit)
for j in range(lenv):
here = tovisit.popleft()
if here[0] == E[0] and here[1] == E[1]: # ugh
print(i)
done = True
break
if s[here[0],here[1]] > i:
s[here[0],here[1]] = i
tovisit.extend(visits(*here))