Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
yield from explore solution in Clear category for Open Labyrinth by veky
def checkio(data):
def explore(path, i, j):
"""Yields all possible solutions starting with path, from (i,j)."""
if i == j == 10: yield path # found a solution
if not data[i][j]: # free way
data[i][j] = 2 # block already traversed path to prevent loops
for i, j, way in (i-1,j,'N'), (i+1,j,'S'), (i,j-1,'W'), (i,j+1,'E'):
yield from explore(path + way, i, j) # explore all four ways
return next(explore('', 1, 1))
April 5, 2017
Comments: