You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
595 B

lines = [ i.split('-') for i in open("input.txt", 'r').read().splitlines()]
paths = []
di = {}
for l in lines:
if l[0] not in di:
di[l[0]] = []
di[l[0]].append(l[1])
if l[1] not in di:
di[l[1]] = []
di[l[1]].append(l[0])
print(di)
def travel(stack, node):
stack.append(node)
if node == 'end':
paths.append(stack.copy())
print(stack)
for n in di[node]:
if n not in stack or n.isupper():
travel(stack,n)
stack.pop()
for start in di['start']:
stack = ['start']
travel(stack, start)
print(len(paths))