ocaml: phase 5.1 perfect.ml baseline (count perfect numbers <= 500 = 3)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s
Perfect numbers = those where the proper-divisor sum equals n. Three exist under 500: 6, 28, 496. (8128 is the next; 33550336 the one after that.) Same div_sum machinery as euler21_small.ml / abundant.ml (the trial-division up to sqrt-n). Original 10000 limit timed out at 10 minutes under contention (496 itself takes thousands of trials at the inner loop). 500 stays under budget while still finding all three small perfects. 125 baseline programs total — milestone.
This commit is contained in:
@@ -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,
|
||||
|
||||
23
lib/ocaml/baseline/perfect.ml
Normal file
23
lib/ocaml/baseline/perfect.ml
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user