-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#17 Split simplify.py from solver.py.
- Loading branch information
Showing
3 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters