-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12a.py
More file actions
executable file
·33 lines (28 loc) · 739 Bytes
/
12a.py
File metadata and controls
executable file
·33 lines (28 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
import numpy as np
import re
with open('12.input', 'r') as f:
segs = re.findall('(\w+)-(\w+)', f.read())
m = {}
for seg in segs:
a, b = seg
if a in m:
m[a].append(b)
else:
m[a] = [b]
if b in m:
m[b].append(a)
else:
m[b] = [a]
sol = []
def move(curr, trail, m):
for dest in m[curr]:
if dest in trail and not dest.isupper():
continue
else:
if dest == 'end':
sol.append(trail + [curr, 'end'])
else:
move(dest, trail + [curr], m)
move('start', [], m)
print(len(sol))