-
-
Save ogwurujohnson/f78b052bd60f1ddf5ea35372d7839001 to your computer and use it in GitHub Desktop.
A BFS algorithm i wrote for solving a proof of mine puzzle in a demo block chain i built
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bfs(): | |
q = Queue() | |
q.enqueue([current_room["room_id"]]) | |
visited = set() | |
while q.size() > 0: | |
path = q.dequeue() | |
v = path[-1] | |
if v not in visited: | |
if v == 182: ### change to whatever room you want to find | |
return path | |
visited.add(v) | |
for key, value in grid[f'{v}'].items(): | |
new_path = list(path) | |
new_path.append(value) | |
q.enqueue(new_path) | |
route_to_shop = bfs() | |
print(route_to_shop) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment