Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Open Labyrinth by stata
#Your code here
#You can import some modules or create additional functions
import copy
def checkio(maze_map):
maze_copy = copy.deepcopy(maze_map)
stack = [('', 1, 1)]
maxX = len(maze_copy)
maxY = len(maze_copy[0])
path_found = False
while(stack):
path_string, x, y = stack.pop()
if (x, y) == (10, 10):
path_found = True
break
maze_copy[x][y] = 1
if y > 0 and maze_copy[x][y-1] == 0:
stack.append((path_string + 'W', x, y-1))
if x < maxX - 1 and maze_copy[x+1][y] == 0:
stack.append((path_string + 'S', x+1, y))
if y < maxY - 1 and maze_copy[x][y+1] == 0:
stack.append((path_string + 'E', x, y+1))
if x > 0 and maze_copy[x-1][y]== 0:
stack.append((path_string + 'N', x-1, y))
if path_found:
return path_string
return None
May 27, 2014
Comments: