Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Open Labyrinth by takapt0226
from collections import deque
def checkio(maze_map):
q = deque([(1, 1)])
path = [[''] * 12 for y in range(0, 12)]
MOVE = {"S": (1, 0), "N": (-1, 0), "W": (0, -1), "E": (0, 1)}
while q:
x, y = q.popleft()
for dir, (dy, dx) in MOVE.items():
(nx, ny) = (x + dx, y + dy)
if maze_map[ny][nx] == 0 and not path[ny][nx]:
path[ny][nx] = path[y][x] + dir
q.append((nx, ny))
return path[10][10]
Feb. 27, 2014
Comments: