Skip to content

Commit

Permalink
#17 Split simplify.py from solver.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
jahodfra committed May 27, 2017
1 parent e09be62 commit adcba4e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
1 change: 0 additions & 1 deletion dynamic.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# distutils: language=c++
#### distutils: sources=search.cpp
from libcpp cimport bool
from libcpp.unordered_set cimport unordered_set
from libcpp.vector cimport vector
Expand Down
45 changes: 45 additions & 0 deletions simplify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/local/bin/python3
"""
Eliminate tracks which can be contructed from already present tracks.
e.g. RRRRSRRRRS, RRRRRRRR -> RRRRRRRR
"""

import argparse
import sys

import track


DESCRIPTION = """\
Take tracks from standard input and print the ones which can be used to
construct the whole set.
Each track should be provided on a new line.
Algorithm for extension:
Extend round track in the opposite direction with S, RL, LR.
Prolong bridges. Replace uphill, downhill with straight segments.
"""


def can_be_simplified(t, set_of_tracks):
return any(st in set_of_tracks for st in t.simplify())


def main():
# TODO: algorithm expects that the shorten piece is also present in the set.
# remove this condition.
parser = argparse.ArgumentParser(description=DESCRIPTION)
args = parser.parse_args()
tracks = set()
for line in sys.stdin:
path = line.strip()
tracks.add(track.Track(path).normalize())
tracks = [t for t in tracks if not can_be_simplified(t, tracks)]
for t in tracks:
print(t.path)


if __name__ == '__main__':
main()
6 changes: 0 additions & 6 deletions solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
'Material', 'straight turns ups, downs pillars')


def can_be_simplified(t, set_of_tracks):
return any(st in set_of_tracks for st in t.simplify())


def normalize_paths(paths):
filtered = []
paths = set(paths)
Expand All @@ -34,8 +30,6 @@ def compute_tracks(material):
paths = normalize_paths(paths)
tracks = [track.Track(p) for p in paths]
tracks = [t for t in tracks if t.is_valid(material)]
set_of_tracks = set(tracks)
tracks = [t for t in tracks if not can_be_simplified(t, set_of_tracks)]
return tracks


Expand Down

0 comments on commit adcba4e

Please sign in to comment.