Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_solution.py #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions 12_Route_Planner/solution.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
def route_exists(from_row, from_column, to_row, to_column, map_matrix):
pass
rows = len(map_matrix)
cols = len(map_matrix[0])

stack = [(from_row, from_column)]
visited = set()

while stack:
current = stack.pop()
if current == (to_row, to_column):
return True
visited.add(current)
row, col = current
neighbors = [(row-1, col), (row+1, col), (row, col-1), (row, col+1)]
for neighbor in neighbors:
n_row, n_col = neighbor
if 0 <= n_row < rows and 0 <= n_col < cols and map_matrix[n_row][n_col] and neighbor not in visited:
stack.append(neighbor)

return False

if __name__ == '__main__':
map_matrix = [
[True, False, False],
[True, True, False],
[False, True, True]
];
]

print(route_exists(0, 0, 2, 2, map_matrix))