Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
16-liner: Path-Finding -> Visited Neighbors are ignored solution in Clear category for Can You Pass? by Stensen
def can_pass(MAP, depart, arrival):
path_value = MAP[depart[0]][depart[1]]
visited = {depart}
neighbr = [depart]
while neighbr:
fore = neighbr.pop()
if fore == arrival:
return True
for i, j in {(1, 0), (0, 1), (0, -1), (-1, 0)}:
try:
x, y = fore[0] + i, fore[1] + j
if MAP[x][y] == path_value and (x, y) not in visited:
visited.add((x, y))
neighbr.append((x, y))
except IndexError: continue
return False
Nov. 10, 2020
Comments: