ocaml: phase 5.1 euler14.ml baseline (longest Collatz under 100, starting n = 97)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
collatz_len walks n through n/2 if even, 3n+1 if odd, counting
steps. Outer loop scans 2..N tracking the best length and arg-best:
let euler14 limit =
let best = ref 0 in
let best_n = ref 0 in
for n = 2 to limit do
let l = collatz_len n in
if l > !best then begin
best := l;
best_n := n
end
done;
!best_n
euler14 100 = 97 (97 generates a 118-step chain)
Real PE14 uses limit = 1_000_000 (answer 837799); 100 exercises the
same algorithm in <2 minutes on our contended host.
116 baseline programs total.
This commit is contained in:
@@ -407,6 +407,13 @@ _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 — euler14.ml baseline (longest Collatz chain
|
||||
starting under N=100 → 97). collatz_len walks n through the
|
||||
iteration n/2 if even, 3n+1 if odd, counting steps. Outer loop
|
||||
scans 2..N tracking best length and arg-best. n=97 generates the
|
||||
118-step chain. Real PE14 uses N=1,000,000 (answer 837799); N=100
|
||||
exercises the same algorithm in <2 minutes. 116 baseline programs
|
||||
total.
|
||||
- 2026-05-09 Phase 5.1 — euler16.ml baseline (digit sum of 2^15 =
|
||||
26). Computes 2^n via for-loop accumulation, then walks the digits
|
||||
via mod 10 / div 10 to sum them. Real PE16 asks for 2^1000 which
|
||||
|
||||
Reference in New Issue
Block a user