Skip to content

Instantly share code, notes, and snippets.

@ogwurujohnson
Created February 12, 2020 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogwurujohnson/f78b052bd60f1ddf5ea35372d7839001 to your computer and use it in GitHub Desktop.
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
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