ocaml: phase 5.1 euler16.ml baseline (digit sum of 2^15 = 26)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Computes 2^n via for-loop multiplication, then walks the digits via
mod 10 / div 10:
let euler16 n =
let p = ref 1 in
for _ = 1 to n do p := !p * 2 done;
let sum = ref 0 in
let m = ref !p in
while !m > 0 do
sum := !sum + !m mod 10;
m := !m / 10
done;
!sum
euler16 15 = 3 + 2 + 7 + 6 + 8 = 26 (= digit sum of 32768)
Real PE16 asks for 2^1000 which exceeds float precision; 2^15 stays
safe and exercises the same digit-decomposition pattern.
115 baseline programs total.
This commit is contained in:
14
lib/ocaml/baseline/euler16.ml
Normal file
14
lib/ocaml/baseline/euler16.ml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
let euler16 n =
|
||||||
|
let p = ref 1 in
|
||||||
|
for _ = 1 to n do p := !p * 2 done;
|
||||||
|
let sum = ref 0 in
|
||||||
|
let m = ref !p in
|
||||||
|
while !m > 0 do
|
||||||
|
sum := !sum + !m mod 10;
|
||||||
|
m := !m / 10
|
||||||
|
done;
|
||||||
|
!sum
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
euler16 15
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
"exception_handle.ml": 4,
|
"exception_handle.ml": 4,
|
||||||
"exception_user.ml": 26,
|
"exception_user.ml": 26,
|
||||||
"euler1.ml": 233168,
|
"euler1.ml": 233168,
|
||||||
|
"euler16.ml": 26,
|
||||||
"euler10.ml": 1060,
|
"euler10.ml": 1060,
|
||||||
"euler2.ml": 4613732,
|
"euler2.ml": 4613732,
|
||||||
"euler25.ml": 55,
|
"euler25.ml": 55,
|
||||||
|
|||||||
@@ -407,6 +407,11 @@ _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 — 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
|
||||||
|
exceeds float precision; 2^15 = 32768 stays safe and exercises the
|
||||||
|
same digit-decomposition pattern. 115 baseline programs total.
|
||||||
- 2026-05-09 Phase 5.1 — euler25.ml baseline (first Fibonacci index
|
- 2026-05-09 Phase 5.1 — euler25.ml baseline (first Fibonacci index
|
||||||
with 12 digits = 55). Iteratively grows two refs while the larger
|
with 12 digits = 55). Iteratively grows two refs while the larger
|
||||||
is below `10^(n-1)`, counting iterations. Real PE25 asks for 1000
|
is below `10^(n-1)`, counting iterations. Real PE25 asks for 1000
|
||||||
|
|||||||
Reference in New Issue
Block a user