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/pancake-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 / pancake-sort / oracle.py` 16 lines ยท 524 bytes Raw Blame History 1 # Independent reference for "Sorting algorithms/Pancake sort" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 a = [23, -7, 61, 4, 0, 38, 15, -7, 90, 2, 11] 4 print(*a) 5 flips = 0 6 for size in range(len(a), 1, -1): 7 m = max(range(size), key=lambda i: (a[i], -i)) 8 if m != size - 1: 9 if m != 0: 10 a[:m + 1] = a[:m + 1][::-1] 11 flips += 1 12 a[:size] = a[:size][::-1] 13 flips += 1 14 assert a == sorted(a) 15 print(*a) 16 print("flips:", flips)