Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simple depth first search solution in Clear category for Open Labyrinth by tokyoamado
from collections import deque
from typing import List
def checkio(maze_map: List[List[int]]) -> str:
row, col = len(maze_map), len(maze_map[0])
stack = deque([((1, 1), maze_map, '')])
while stack:
(r, c), field, path = stack.pop()
if (r, c) == (row -2, col - 2):
return path
field[r][c] = 1
news = (
((i, j), d) for (i, j), d
in (((r + 1, c), 'S'), ((r, c + 1), 'E'), ((r - 1, c), 'N'), ((r, c - 1), 'W'))
if field[i][j] == 0)
for p, d in news:
stack.append((p, field[:], path + d))
May 8, 2019