Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
clear&readable recursion + visited list solution in Clear category for Can You Pass? by m.kurapov
def can_pass(matrix, first, second):
visited = []
def try_step(y,x):
if ( 0 <= y < len(matrix)
and 0 <= x < len(matrix[0])
and matrix[y][x] == matrix[first[0]][first[1]]
and (y,x) not in visited
):
visited.append((y,x))
return True if (y,x) == second else try_step(y+1,x) or \
try_step(y,x+1) or \
try_step(y-1,x) or \
try_step(y,x-1)
return False
return try_step(*first)
Feb. 23, 2020