From da96a79104d844d37885640c0d18feb00b0c72ef Mon Sep 17 00:00:00 2001 From: giles Date: Sun, 10 May 2026 00:36:29 +0000 Subject: [PATCH] ocaml: phase 5.1 abundant.ml baseline (count abundant numbers < 100 = 21) A number n is abundant if its proper-divisor sum exceeds n. Reuses the trial-division div_sum helper: let count_abundant n = let c = ref 0 in for i = 12 to n - 1 do if div_sum i > i then c := !c + 1 done; !c count_abundant 100 = 21 Abundant numbers under 100, starting at 12, 18, 20, 24, 30, 36, 40, 42, 48, 54, 56, 60, 66, 70, 72, 78, 80, 84, 88, 90, 96 -> 21. Companion to euler21_small.ml (amicable). The classification: perfect: d(n) = n (e.g. 6, 28) abundant: d(n) > n (e.g. 12, 18) deficient:d(n) < n (everything else) 124 baseline programs total. --- lib/ocaml/baseline/abundant.ml | 23 +++++++++++++++++++++++ lib/ocaml/baseline/expected.json | 1 + plans/ocaml-on-sx.md | 5 +++++ 3 files changed, 29 insertions(+) create mode 100644 lib/ocaml/baseline/abundant.ml diff --git a/lib/ocaml/baseline/abundant.ml b/lib/ocaml/baseline/abundant.ml new file mode 100644 index 00000000..c5b17781 --- /dev/null +++ b/lib/ocaml/baseline/abundant.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_abundant n = + let c = ref 0 in + for i = 12 to n - 1 do + if div_sum i > i then c := !c + 1 + done; + !c + +;; + +count_abundant 100 diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index d995d935..88a56448 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -1,4 +1,5 @@ { + "abundant.ml": 21, "ackermann.ml": 125, "adler32.ml": 300286872, "anagram_check.ml": 2, diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index f779c07c..34acfbec 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,11 @@ _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 — 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 + 205. 21 abundant numbers under 100, starting at 12, 18, 20, 24... + 124 baseline programs total. - 2026-05-10 Phase 5.1 — euler36.ml baseline (sum of double-base palindromes ≤ 1000 = 1772). Numbers that read the same in base 10 and base 2: 1, 3, 5, 7, 9, 33, 99, 313, 585, 717. Sum = 1772.