Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/strand-sort/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / strand-sort / oracle.py` 23 lines ยท 762 bytes Raw Blame History 1 # Independent reference for "Sorting algorithms/Strand sort" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 def strand_sort(a): 4 a = list(a) 5 out = [] 6 while a: 7 strand, rest = [a[0]], [] 8 for v in a[1:]: 9 (strand if v >= strand[-1] else rest).append(v) 10 merged = [] 11 i = j = 0 12 while i < len(out) or j < len(strand): 13 if j >= len(strand) or (i < len(out) and out[i] <= strand[j]): 14 merged.append(out[i]); i += 1 15 else: 16 merged.append(strand[j]); j += 1 17 out, a = merged, rest 18 return out 19 a = [5, 1, 4, 2, 0, 9, 6, 3, 8, 7, -2, 11] 20 print(*a) 21 s = strand_sort(a) 22 assert s == sorted(a) 23 print(*s)