Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Open Labyrinth by PawlakBartosz43
def checkio(maze_map):
visited = [[0 for col in range(12)] for row in range(12)] #create a 12x12 grid of zeroes
def route(maze_map, x, y, result):
visited[x][y] = 1 #mark your current position as visited
if(x == 10 and y == 10): #if the coordinates are (10,10), end the program and return what we have
return result
if(maze_map[x][y+1] == 0 and visited[x][y+1] == 0): #if the tile on your right is not blocked and you've not been to it before - go there
dir = route(maze_map, x, y+1, result+'E') #using recursion we slowly progress, taking the result with us
if(dir):
return dir
if(maze_map[x+1][y] == 0 and visited[x+1][y] == 0): #same as above but for 'down', etc.
dir = route(maze_map, x+1, y, result+'S')
if(dir):
return dir
if(maze_map[x][y-1] == 0 and visited[x][y-1] == 0):
dir = route(maze_map, x, y-1, result+'W')
if(dir):
return dir
if(maze_map[x-1][y] == 0 and visited[x-1][y] == 0):
dir = route(maze_map, x-1, y, result+'N')
if(dir):
return dir
return ''
result = route(maze_map, 1, 1, '') #start here, at (1,1)
return result
Dec. 12, 2016