ocaml: phase 5.1 euler4_small.ml baseline (largest 2-digit palindrome product = 9009)
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
Scaled-down Project Euler #4. Real version uses 3-digit numbers yielding 906609 = 913 * 993; that's an 810k-iteration nested loop that times out under our contended-host spec-level evaluator. The 2-digit version (10..99) is fast enough and tests the same algorithm: 9009 = 91 * 99 (the only 2-digit-product palindrome > 9000) Implementation: is_pal n index-walk comparing s.[i] to s.[len-1-i] euler4 lo hi nested for with running max + early-skip via 'p > !m && is_pal p' short-circuit 111 baseline programs total.
This commit is contained in:
21
lib/ocaml/baseline/euler4_small.ml
Normal file
21
lib/ocaml/baseline/euler4_small.ml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
let is_pal n =
|
||||||
|
let s = string_of_int n in
|
||||||
|
let len = String.length s in
|
||||||
|
let p = ref true in
|
||||||
|
for i = 0 to len / 2 - 1 do
|
||||||
|
if s.[i] <> s.[len - 1 - i] then p := false
|
||||||
|
done;
|
||||||
|
!p
|
||||||
|
|
||||||
|
let euler4 lo hi =
|
||||||
|
let m = ref 0 in
|
||||||
|
for a = lo to hi do
|
||||||
|
for b = a to hi do
|
||||||
|
let p = a * b in
|
||||||
|
if p > !m && is_pal p then m := p
|
||||||
|
done
|
||||||
|
done;
|
||||||
|
!m
|
||||||
|
;;
|
||||||
|
|
||||||
|
euler4 10 99
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
"euler1.ml": 233168,
|
"euler1.ml": 233168,
|
||||||
"euler10.ml": 1060,
|
"euler10.ml": 1060,
|
||||||
"euler2.ml": 4613732,
|
"euler2.ml": 4613732,
|
||||||
|
"euler4_small.ml": 9009,
|
||||||
"euler5.ml": 232792560,
|
"euler5.ml": 232792560,
|
||||||
"euler6.ml": 25164150,
|
"euler6.ml": 25164150,
|
||||||
"euler9.ml": 31875000,
|
"euler9.ml": 31875000,
|
||||||
|
|||||||
@@ -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 — euler4_small.ml baseline (largest 2-digit
|
||||||
|
palindrome product = 9009 = 91 * 99). Scaled-down Project Euler
|
||||||
|
#4 (real version uses 3-digit numbers, 906609; that's 810k inner
|
||||||
|
iterations and would time out under contention). Tests palindrome
|
||||||
|
predicate via index-walk + nested for. 111 baseline programs total.
|
||||||
- 2026-05-09 Phase 5.1 — euler10.ml baseline (sum of primes ≤ 100 =
|
- 2026-05-09 Phase 5.1 — euler10.ml baseline (sum of primes ≤ 100 =
|
||||||
1060, scaled-down Project Euler #10). Sieve of Eratosthenes
|
1060, scaled-down Project Euler #10). Sieve of Eratosthenes
|
||||||
followed by a sum loop. Used 100 instead of 2 million to fit our
|
followed by a sum loop. Used 100 instead of 2 million to fit our
|
||||||
|
|||||||
Reference in New Issue
Block a user