Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Can You Pass? by Kisielev
def can_pass(matrix, first, second):
proper_path = matrix[first[0]][first[1]]
visited = {first}
front = [first]
while front:
head = front.pop()
if head == second:
return True
for i, j in ((-1,0),(0,-1),(1,0),(0,1)):
try:
x = head[0]+i
y = head[1]+j
if matrix[x][y] == proper_path and (x, y) not in visited:
visited.add((x, y))
front.append((x, y))
except IndexError:
continue
return False
Nov. 23, 2018
Comments: