Untitled
unknown
plain_text
8 months ago
734 B
6
Indexable
def explore(i, j):
global solution, visited
if (0 <= i < n) and (0 <= j < m) and (maze[i][j] != '#') and (not visited[i][j]):
visited[i][j] = True
if maze[i][j] == 'B':
solution = True
explore(i - 1, j) # up
explore(i + 1, j) # down
explore(i, j - 1) # left
explore(i, j + 1) # right
def find(symbol):
for i, row in enumerate(maze):
j = row.find(symbol)
if j >= 0:
return (i, j)
n, m = [int(x) for x in input("Enter input: ").split()]
maze = [input() for _ in range(n)]
solution = False
visited = [[False] * m for _ in range(n)]
explore(*find('A'))
if solution:
print("path from A to B exists")
else:
print("no path")Editor is loading...
Leave a Comment