Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
basic recursion solution in Clear category for Open Labyrinth by Tarty
START = (1,1)
EXIT = (10, 10)
WAYS = {"S": (1, 0), "N": (-1, 0), "W": (0, -1), "E": (0, 1)}
move = lambda pos, move: tuple(sum(x) for x in zip(pos, move))
def checkio(maze_map, position = START, path = ""):
if position == EXIT:
return path
for dir in WAYS:
newPosition = move(position, WAYS[dir])
if newPosition == EXIT:
return path + dir
elif not maze_map[newPosition[0]][newPosition[1]]:
maze_map[position[0]][position[1]] = 1
success = checkio(maze_map, newPosition, path + dir)
if success: return success
else : maze_map[position[0]][position[1]] = 0
return None
Dec. 12, 2014
Comments: