Created
July 19, 2016 16:15
-
-
Save leegao/4c05de1e393ffaa4b756cd56eb33835a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 getAllNeighbors(origin, steps = 1): | |
seen = {origin} | |
worklist = [origin] | |
while steps: | |
new_worklist = [] | |
for next in worklist: | |
seen.add(next) | |
for neighbor in next.get_all_neighbors(15): | |
if neighbor not in seen: new_worklist.append(neighbor) | |
worklist = new_worklist | |
steps -= 1 | |
return seen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment