Commit 0e835b88 authored by Eddie Schoute's avatar Eddie Schoute
Browse files

Add main function for script

parent 9ec0046c
......@@ -73,11 +73,22 @@ def perm_to_01(L, i, j):
median = (j - i) // 2
return L[:i] + [int(sorted_subseq.index(k) > median) for k in subseq] + L[j + 1:]
def permutationsort_divideconquer_tbs(L, i, j):
def permutationsort_divideconquer_tbs(L):
"""Routes the given permutation using reversals. Returns the reversals"""
j = max(L)
return permutationsort_divideconquer_tbs(L, 0, j)
def permutationsort_divideconquer_tbs(L, i=None, j=None):
"""
Sorts the given permutations L from index i to j (inclusive) using a divide and conquer approach. Returns a list of
reversals used to perform the sort.
"""
# Set default params
if i == None:
i = min(L)
if j == None:
j = max(L)
if i == j:
return []
T = perm_to_01(L, i, j)
......
......@@ -120,3 +120,12 @@ def main(NUM_PERMS_PER_LENGTH, LENGTH_FROM, LENGTH_TO):
algnames = ['OES', 'GDC(TBS)', 'GDC(ATBS)']
algs = [SBR.odd_even_sort, TripartiteBinarySort.GDC_TBS, AdaptiveTBS.GDC_ATBS]
new_rand_perms_file(algs, algnames, list(range(LENGTH_FROM,LENGTH_TO + 1)), NUM_PERMS_PER_LENGTH)
# Now you can run `echo "0 1 3 2" | python main.py`
if __name__ == "__main__":
import sys
for line in sys.stdin:
perm = [int(el) for el in line.split()]
reversals = TripartiteBinarySort.permutationsort_divideconquer_tbs(perm)
print(reversals) # TODO: Implement pretty print
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment