Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Open Labyrinth by saklar13
def checkio(maze_map):
d_map = {(i, j): maze_map[i][j] for i in range(len(maze_map))
for j in range(len(maze_map))}
vizited = set()
directions = {'S':(1,0), 'N':(-1,0), 'E':(0,1), 'W': (0,-1)}
way = (1, 1)
path = ''
old_way = []
while way != (10, 10):
for d in ('SENW'):
new_way = tuple(map(sum, zip(way, directions[d])))
if d_map[new_way] or new_way in vizited: continue
else:
vizited.add(new_way)
old_way.append(way)
way = new_way
path += d
break
else:
way = old_way.pop()
path = path[:-1]
else: return path
Jan. 10, 2015