Skip to content

Instantly share code, notes, and snippets.

@alaniwi
Last active June 19, 2020 14:20
Show Gist options
  • Save alaniwi/2d57d30a8f7bb418d5ee698ab532a6c2 to your computer and use it in GitHub Desktop.
Save alaniwi/2d57d30a8f7bb418d5ee698ab532a6c2 to your computer and use it in GitHub Desktop.
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))
[['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