ocaml: phase 5.1 euler2.ml baseline (Project Euler #2, even Fib <= 4M = 4613732)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s

Sum of even-valued Fibonacci numbers up to 4,000,000:

  let euler2 limit =
    let a = ref 1 in
    let b = ref 2 in
    let sum = ref 0 in
    while !a <= limit do
      if !a mod 2 = 0 then sum := !sum + !a;
      let c = !a + !b in
      a := !b;
      b := c
    done;
    !sum

Sequence: 1, 2, 3, 5, 8, 13, 21, 34, ... Only every third term
(2, 8, 34, 144, ...) is even. Sum below 4M: 4613732.

101 baseline programs total.
This commit is contained in:
2026-05-09 20:05:45 +00:00
parent 53968c2480
commit 4840a9f660
3 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
let euler2 limit =
let a = ref 1 in
let b = ref 2 in
let sum = ref 0 in
while !a <= limit do
if !a mod 2 = 0 then sum := !sum + !a;
let c = !a + !b in
a := !b;
b := c
done;
!sum
;;
euler2 4000000

View File

@@ -25,6 +25,7 @@
"exception_handle.ml": 4,
"exception_user.ml": 26,
"euler1.ml": 233168,
"euler2.ml": 4613732,
"expr_eval.ml": 16,
"expr_simp.ml": 22,
"factorial.ml": 3628800,

View File

@@ -407,6 +407,11 @@ _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 — euler2.ml baseline (Project Euler #2, sum
of even Fibonacci ≤ 4M = 4613732). Iterative two-ref Fibonacci,
accumulating only even terms. Sequence: 1, 2, 3, 5, 8, 13, 21,
34... only 2, 8, 34, 144, ... contribute. 101 baseline programs
total.
- 2026-05-09 Phase 5.1 — euler1.ml baseline (Project Euler #1, sum
of multiples of 3 or 5 below 1000 = 233168). Trivial DSL exercise
but symbolically meaningful: this is the 100th baseline program.