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,
|
||||
"euler10.ml": 1060,
|
||||
"euler2.ml": 4613732,
|
||||
"euler25.ml": 55,
|
||||
"euler3.ml": 29,
|
||||
"euler4_small.ml": 9009,
|
||||
"euler5.ml": 232792560,
|
||||
|
||||
Reference in New Issue
Block a user