Last active
June 19, 2020 14:20
-
-
Save alaniwi/2d57d30a8f7bb418d5ee698ab532a6c2 to your computer and use it in GitHub Desktop.
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 explore(l, c, t): # l = 2d list of connections; c = current node; t = target node | |
if c == t: # base case | |
return [[c]] | |
else: # recursive case | |
conns = [] | |
if c in i: | |
conns.extend([[c] + conn | |
for conn in explore([k for k in l if i != k], | |
(i[0] if c == i[1] else i[1]), | |
t) | |
if c not in conn]) | |
return conns | |
conns = [('a', 'b'), ('b', 'c'), ('d', 'e'), ('c', 'd'), ('d', 'b'), ('a', 'd')] | |
target = 'e' | |
start = 'a' | |
print(explore(conns, start, target)) |
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
[['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'd', 'e'], ['a', 'd', 'e']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment