ocaml: phase 5.1 pancake_sort.ml baseline (in-place pancake sort, 9 flips -> 910)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s

Each pass:
  1. find_max in [0..size-1]
  2. if max not at the right end, flip max to position 0 (if needed)
  3. flip the size-prefix to push max to the end

Inner 'flip k' reverses prefix [0..k] using two pointer refs lo/hi.
Inner 'find_max k' walks 1..k tracking the max-position.

  pancake_sort [3;1;4;1;5;9;2;6]
  = 9 flips * 100 + a.(0) + a.(n-1)
  = 9 * 100 + 1 + 9
  = 910

The output combines flip count and sorted endpoints, so the test
verifies both that the sort terminates and that it sorts correctly.

Tests two inner functions closing over the same Array, ref-based
two-pointer flip, and downto loop with conditional flip dispatch.

77 baseline programs total.
This commit is contained in:
2026-05-09 16:03:22 +00:00
parent ce013fa138
commit 5d71be364e
3 changed files with 43 additions and 0 deletions

View File

@@ -52,6 +52,7 @@
"mutable_record.ml": 10,
"option_match.ml": 5,
"palindrome.ml": 4,
"pancake_sort.ml": 910,
"pascal.ml": 252,
"pi_leibniz.ml": 314,
"prefix_sum.ml": 66,