Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Sets solution in Clear category for Can You Pass? by Talim42
def nhood(x, y):
return {(x - 1, y), (x, y - 1), (x + 1, y), (x, y + 1)}
def can_pass(matrix, first, second):
""" deremines if second point can be reached by ground """
ground = {(y, x) for y in range(len(matrix)) for x in range(len(matrix[0]))\
if matrix[y][x] == matrix[first[0]][first[1]]}
achievables, todo = set(), {first}
while todo:
todo = todo | (nhood(*todo.pop()) & ground - achievables)
achievables = achievables | todo
if second in achievables:
return True
return False
Sept. 22, 2014
Comments: