-
Notifications
You must be signed in to change notification settings - Fork 1
/
solver.py
executable file
·76 lines (61 loc) · 1.96 KB
/
solver.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/local/bin/python3
import argparse
import collections
import dynamic
import track
Material = collections.namedtuple(
'Material', 'straight turns ups, downs pillars')
def normalize_paths(paths):
filtered = []
paths = set(paths)
while paths:
path = paths.pop()
min_path = path
for symetric_path in track.all_symetries(path):
paths.discard(symetric_path)
if symetric_path < min_path:
min_path = symetric_path
filtered.append(min_path)
return filtered
def compute_tracks(material):
paths = dynamic.find_all_paths(material)
paths = normalize_paths(paths)
tracks = [track.Track(p) for p in paths]
tracks = [t for t in tracks if t.is_valid(material)]
return tracks
DESCRIPTION = """\
Write out all enclosed path with given set of elements.
Each path is written on a new line.
Elements: S - straight segment, U - uphill segment, D - downhill segment,
R - turn right, L - turn left\
"""
def main():
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument(
'--turns',
dest='turns', type=int, default=12, help='number of turn segments')
parser.add_argument(
'--straight',
dest='straight', type=int, default=4,
help='number of straight segments')
parser.add_argument(
'--ups',
dest='ups', type=int, default=2, help='number of uphill segments')
parser.add_argument(
'--downs',
dest='downs', type=int, default=2, help='number of downhill segments')
parser.add_argument(
'--pillars',
dest='pillars', type=int, default=4, help='number of pillars')
args = parser.parse_args()
material = Material(
turns=args.turns,
straight=args.straight,
ups=args.ups,
downs=args.downs,
pillars=args.pillars)
tracks = compute_tracks(material)
for t in tracks:
print(t.path)
if __name__ == '__main__':
main()