ocaml: phase 5.1 shuffle.ml baseline (Fisher-Yates with deterministic Random)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s

In-place Fisher-Yates shuffle using:

  Random.init 42                  deterministic seed
  let a = Array.of_list xs
  for i = n - 1 downto 1 do       reverse iteration
    let j = Random.int (i + 1)
    let tmp = a.(i) in
    a.(i) <- a.(j);
    a.(j) <- tmp
  done

Sum is invariant under permutation, so the test value (55 for
[1..10] = 1+2+...+10) verifies the shuffle is a valid permutation
regardless of which permutation the seed yields.

Exercises Random.init / Random.int + Array.of_list / to_list /
length / arr.(i) / arr.(i) <- v + downto loop + multi-statement
sequencing within for-body.

33 baseline programs total.
This commit is contained in:
2026-05-09 07:31:33 +00:00
parent 90418c120b
commit 75a1adbbd5
3 changed files with 23 additions and 0 deletions

View File

@@ -29,6 +29,7 @@
"quicksort.ml": 44,
"roman.ml": 44,
"safe_div.ml": 20,
"shuffle.ml": 55,
"sieve.ml": 15,
"sum_squares.ml": 385,
"unique_set.ml": 9,