ocaml: phase 5.1 euler5.ml baseline (smallest multiple of 1..20 = 232792560)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 29s

Iteratively takes lcm of running result with i:

  let rec gcd a b = if b = 0 then a else gcd b (a mod b)
  let lcm a b = a * b / gcd a b
  let euler5 n =
    let r = ref 1 in
    for i = 2 to n do
      r := lcm !r i
    done;
    !r

  euler5 20 = 232792560
            = 2^4 * 3^2 * 5 * 7 * 11 * 13 * 17 * 19

Tests gcd_lcm composition (iter 140) on a fresh problem.

109 baseline programs total.
This commit is contained in:
2026-05-09 21:35:59 +00:00
parent cecde8733a
commit 00ffba9306
3 changed files with 18 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let lcm a b = a * b / gcd a b
let euler5 n =
let r = ref 1 in
for i = 2 to n do
r := lcm !r i
done;
!r
;;
euler5 20

View File

@@ -27,6 +27,7 @@
"exception_user.ml": 26,
"euler1.ml": 233168,
"euler2.ml": 4613732,
"euler5.ml": 232792560,
"euler6.ml": 25164150,
"euler9.ml": 31875000,
"expr_eval.ml": 16,

View File

@@ -407,6 +407,12 @@ _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 — euler5.ml baseline (Project Euler #5,
smallest number divisible by all 1..20 = 232792560). Iteratively
takes lcm of running result with i for i=2..n; lcm via gcd via
Euclidean. 232792560 = 2^4 * 3^2 * 5 * 7 * 11 * 13 * 17 * 19.
Tests two-line gcd/lcm + for-loop accumulator pattern. 109
baseline programs total.
- 2026-05-09 Phase 5.1 — partition.ml baseline (stable partition by
predicate, 30*100 + 25 = 3025). Two ref lists accumulating in
reverse, then List.rev'd — preserves original order. Test: