diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 88a56448..07296ad2 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -94,6 +94,7 @@ "pancake_sort.ml": 910, "pascal.ml": 252, "peano.ml": 30, + "perfect.ml": 3, "pi_leibniz.ml": 314, "prefix_sum.ml": 66, "pretty_table.ml": 64, diff --git a/lib/ocaml/baseline/perfect.ml b/lib/ocaml/baseline/perfect.ml new file mode 100644 index 00000000..2ec3c4a9 --- /dev/null +++ b/lib/ocaml/baseline/perfect.ml @@ -0,0 +1,23 @@ +let div_sum n = + let s = ref 1 in + let i = ref 2 in + while !i * !i <= n do + if n mod !i = 0 then begin + s := !s + !i; + let q = n / !i in + if q <> !i then s := !s + q + end; + i := !i + 1 + done; + if n = 1 then 0 else !s + +let count_perfect limit = + let c = ref 0 in + for n = 2 to limit do + if div_sum n = n then c := !c + 1 + done; + !c + +;; + +count_perfect 500 diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 34acfbec..4de83aaf 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-10 Phase 5.1 — perfect.ml baseline (count perfect numbers + ≤ 500 = 3). Perfect numbers = those where d(n) = n. Three under + 500: 6, 28, 496. (8128 is the next.) Same div_sum machinery as + euler21_small / abundant. Original 10000 limit timed out under + contention; 500 stays under budget. 125 baseline programs total — + milestone. - 2026-05-10 Phase 5.1 — abundant.ml baseline (count abundant numbers < 100 = 21). Abundant means d(n) > n where d(n) is the proper- divisor sum. Reuses the trial-division div_sum helper from iter