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

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:
2026-05-09 22:31:27 +00:00
parent 320d78a993
commit 5959989324
3 changed files with 24 additions and 0 deletions

View 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

View File

@@ -28,6 +28,7 @@
"euler1.ml": 233168,
"euler10.ml": 1060,
"euler2.ml": 4613732,
"euler25.ml": 55,
"euler3.ml": 29,
"euler4_small.ml": 9009,
"euler5.ml": 232792560,