Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Open Labyrinth by eugene100372
from typing import List
d={(1,0):'S',(-1,0):'N',(0,1):'E',(0,-1):'W'}
def neighbors(i,j):
return set((i+di,j+dj) for di,dj in d)
def checkio(maze_map: List[List[int]]) -> str:
s=set((i,j) for i in range(12) for j in range(12) if maze_map[i][j]==0)
s.remove((1,1))
new={(1,1)}
steps=[new]
while (10,10) not in new:
newest=set()
for el in new:
newest|=neighbors(*el)&s
new=newest-new
s-=new
steps.append(new)
steps.pop()
res=''
nxt=(10,10)
while steps:
prev=(neighbors(*nxt)&steps.pop()).pop()
res=d[nxt[0]-prev[0],nxt[1]-prev[1]]+res
nxt=prev
return res
Sept. 22, 2020
Comments: