ocaml: phase 5.1 euler25.ml baseline (first 12-digit Fibonacci index = 55)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Iteratively grows two refs while the larger is below 10^(n-1),
counting iterations:
let euler25 n =
let a = ref 1 in
let b = ref 1 in
let i = ref 2 in
let target = ref 1 in
for _ = 1 to n - 1 do target := !target * 10 done;
while !b < !target do
let c = !a + !b in
a := !b;
b := c;
i := !i + 1
done;
!i
euler25 12 = 55 (F(55) = 139_583_862_445, 12 digits)
Real PE25 asks for 1000 digits (answer 4782); 12 keeps within
safe-int while exercising the identical algorithm.
114 baseline programs total — 200 iterations landed.
This commit is contained in:
17
lib/ocaml/baseline/euler25.ml
Normal file
17
lib/ocaml/baseline/euler25.ml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
let euler25 n =
|
||||||
|
let a = ref 1 in
|
||||||
|
let b = ref 1 in
|
||||||
|
let i = ref 2 in
|
||||||
|
let target = ref 1 in
|
||||||
|
for _ = 1 to n - 1 do target := !target * 10 done;
|
||||||
|
while !b < !target do
|
||||||
|
let c = !a + !b in
|
||||||
|
a := !b;
|
||||||
|
b := c;
|
||||||
|
i := !i + 1
|
||||||
|
done;
|
||||||
|
!i
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
euler25 12
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
"euler1.ml": 233168,
|
"euler1.ml": 233168,
|
||||||
"euler10.ml": 1060,
|
"euler10.ml": 1060,
|
||||||
"euler2.ml": 4613732,
|
"euler2.ml": 4613732,
|
||||||
|
"euler25.ml": 55,
|
||||||
"euler3.ml": 29,
|
"euler3.ml": 29,
|
||||||
"euler4_small.ml": 9009,
|
"euler4_small.ml": 9009,
|
||||||
"euler5.ml": 232792560,
|
"euler5.ml": 232792560,
|
||||||
|
|||||||
@@ -407,6 +407,12 @@ _Newest first._
|
|||||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||||
recursive match, List.append, List.fold_left.
|
recursive match, List.append, List.fold_left.
|
||||||
|
- 2026-05-09 Phase 5.1 — euler25.ml baseline (first Fibonacci index
|
||||||
|
with 12 digits = 55). Iteratively grows two refs while the larger
|
||||||
|
is below `10^(n-1)`, counting iterations. Real PE25 asks for 1000
|
||||||
|
digits (= 4782); 12 keeps within safe-int while exercising the
|
||||||
|
identical algorithm. 114 baseline programs total — and 200
|
||||||
|
iterations landed.
|
||||||
- 2026-05-09 Phase 5.1 — euler3.ml baseline (largest prime factor of
|
- 2026-05-09 Phase 5.1 — euler3.ml baseline (largest prime factor of
|
||||||
13195 = 29; PE3's worked example). Trial-division streaming: when
|
13195 = 29; PE3's worked example). Trial-division streaming: when
|
||||||
the current factor divides m, divide and update largest; otherwise
|
the current factor divides m, divide and update largest; otherwise
|
||||||
|
|||||||
Reference in New Issue
Block a user