Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Depth-first search solution in Clear category for Open Labyrinth by 1-more
def checkio(maze):
enter, exit, visited, stack= (0,0), (10,10), set(), []
def explore(x, y, path):
if maze[x][y]==0 and (x,y) not in visited:
stack.append((x, y, path))
visited.add((x, y))
explore(1, 1, '')
while stack:
x, y, path= stack.pop(0)
if (x,y)==exit: return path
for dx, dy, dp in [(1, 0,'S'), (-1, 0, 'N'), (0, -1, 'W'), (0, 1, 'E')]:
explore(x+dx, y+dy, path+dp)
return ''
Feb. 21, 2018