Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using queue solution in Clear category for Open Labyrinth by davejlin
def get_neighbors(maze_map, row, col):
pos = [
((row, col+1), "E"),
((row, col-1), "W"),
((row-1, col), "N"),
((row+1, col), "S")
]
return [((r,c),d) for (r,c),d in pos if maze_map[r][c] == 0]
def checkio(maze_map):
queue = [((1,1), "")]
visited = set()
while queue:
pos, path = queue.pop(0)
if pos == (10, 10): return path
elif pos in visited: continue
for neigh_pos, direction in get_neighbors(maze_map, pos[0], pos[1]):
if neigh_pos in visited: continue
queue.append((neigh_pos, path + direction))
visited.add(pos)
return None
Dec. 10, 2016