ocaml: phase 5.1 catalan.ml baseline (Catalan number C(5) = 42)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
DP recurrence:
C(0) = 1
C(n) = sum_{j=0}^{n-1} C(j) * C(n-1-j)
let catalan n =
let dp = Array.make (n + 1) 0 in
dp.(0) <- 1;
for i = 1 to n do
for j = 0 to i - 1 do
dp.(i) <- dp.(i) + dp.(j) * dp.(i - 1 - j)
done
done;
dp.(n)
C(5) = 42 — also the count of distinct binary trees with 5 internal
nodes, balanced paren strings of length 10, monotonic lattice paths,
etc.
106 baseline programs total.
This commit is contained in:
13
lib/ocaml/baseline/catalan.ml
Normal file
13
lib/ocaml/baseline/catalan.ml
Normal file
@@ -0,0 +1,13 @@
|
||||
let catalan n =
|
||||
let dp = Array.make (n + 1) 0 in
|
||||
dp.(0) <- 1;
|
||||
for i = 1 to n do
|
||||
for j = 0 to i - 1 do
|
||||
dp.(i) <- dp.(i) + dp.(j) * dp.(i - 1 - j)
|
||||
done
|
||||
done;
|
||||
dp.(n)
|
||||
|
||||
;;
|
||||
|
||||
catalan 5
|
||||
@@ -18,6 +18,7 @@
|
||||
"bsearch.ml": 7,
|
||||
"caesar.ml": 215,
|
||||
"calc.ml": 13,
|
||||
"catalan.ml": 42,
|
||||
"closures.ml": 315,
|
||||
"coin_change.ml": 6,
|
||||
"count_change.ml": 406,
|
||||
|
||||
@@ -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 — catalan.ml baseline (Catalan number C(5)
|
||||
via DP recurrence = 42). DP recurrence `C(n) = sum_{j=0}^{n-1}
|
||||
C(j) * C(n-1-j)`. C(5) = 42 — also the count of distinct binary
|
||||
trees with 5 internal nodes, balanced paren strings of length
|
||||
10, etc. Tests nested for-loop over Array with arr.(i) read +
|
||||
write. 106 baseline programs total.
|
||||
- 2026-05-09 Phase 5.1 — fizz_classifier.ml baseline (FizzBuzz with
|
||||
polymorphic variants, 1..30 weighted score = 540). Two functions:
|
||||
classify maps i → ` `FizzBuzz | `Fizz | `Buzz | `Num n``, and score
|
||||
|
||||
Reference in New Issue
Block a user