diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 64d27e66..019e45a1 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -30,6 +30,7 @@ "fraction.ml": 7, "frequency.ml": 5, "gcd_lcm.ml": 60, + "gray_code.ml": 136, "grep_count.ml": 3, "grid_paths.ml": 210, "group_consec.ml": 53, diff --git a/lib/ocaml/baseline/gray_code.ml b/lib/ocaml/baseline/gray_code.ml new file mode 100644 index 00000000..a5172d56 --- /dev/null +++ b/lib/ocaml/baseline/gray_code.ml @@ -0,0 +1,12 @@ +let gray n = + let m = 1 lsl n in + let result = Array.make m 0 in + for i = 0 to m - 1 do + result.(i) <- i lxor (i lsr 1) + done; + result + +;; + +let g = gray 4 in +Array.fold_left (+) 0 g + Array.length g diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 2c5c9359..0632af61 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,12 @@ _Newest first._ binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree * 'a tree`) with insert + in-order traversal. Tests parametric ADT, recursive match, List.append, List.fold_left. +- 2026-05-09 Phase 5.1 — gray_code.ml baseline (4-bit binary + reflected Gray code, sum 120 + length 16 = 136). Single-formula + generation: `gray[i] = i lxor (i lsr 1)`. Outputs a permutation of + 0..15, so its sum is the same 120 as the natural sequence; the + length-16 confirms 2^4 entries. Tests `lsl`/`lxor`/`lsr` together + and Array.make + Array.fold_left. 95 baseline programs total. - 2026-05-09 Phase 5.1 — max_run.ml baseline (longest consecutive run, sum of three test cases = 4+1+0 = 5). Walks list with `Some y when y = x` guard pattern in match for the prev-value