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.

30 lines
804 B

2 years ago
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])
def travel(stack, node):
stack.append(node)
if node == 'end':
paths.append(stack.copy())
for n in di[node]:
#if n not in stack or n.isupper():
if (not(n in stack and any(stack.count(i) > 1 for i in [j for j in stack if j.islower()])) or n.isupper()) and n != 'start' and stack[-1] != 'end':
2 years ago
travel(stack,n)
stack.pop()
for start in di['start']:
stack = ['start']
travel(stack, start)
print(len([i for i in paths if not any(i.count(j) > 1 for j in i if j.islower())]))
2 years ago
print(len(paths))