parent
6aba85fae4
commit
782fb6b13d
3 changed files with 63 additions and 0 deletions
@ -0,0 +1,31 @@ |
||||
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)) |
@ -0,0 +1,25 @@ |
||||
qi-UD |
||||
jt-br |
||||
wb-TF |
||||
VO-aa |
||||
UD-aa |
||||
br-end |
||||
end-HA |
||||
qi-br |
||||
br-HA |
||||
UD-start |
||||
TF-qi |
||||
br-hf |
||||
VO-hf |
||||
start-qi |
||||
end-aa |
||||
hf-HA |
||||
hf-UD |
||||
aa-hf |
||||
TF-hf |
||||
VO-start |
||||
wb-aa |
||||
UD-wb |
||||
KX-wb |
||||
qi-VO |
||||
br-TF |
@ -0,0 +1,7 @@ |
||||
start-A |
||||
start-b |
||||
A-c |
||||
A-b |
||||
b-d |
||||
A-end |
||||
b-end |
Loading…
Reference in new issue