Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
StopIteration solution in Clear category for Open Labyrinth by gyahun_dash
def checkio(maze, start=(1, 1), goal=(10, 10)):
def explore(route, moves=''):
if route[-1] == goal: raise StopIteration(moves)
y, x = route[-1]
positions = (y - 1, x), (y, x + 1), (y, x - 1), (y + 1, x)
reachable = lambda r, c: maze[r][c] == 0 and (r, c) not in route
for pos, direct in zip(positions, 'NEWS'):
if reachable(*pos): explore(route + [pos], moves + direct)
try: explore([start])
except StopIteration as found: return found.value
else: return ''
Oct. 18, 2014
Comments: