ocaml: phase 5.1 euler29_small.ml baseline (distinct a^b for 2<=a,b<=5 = 15)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 40s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 40s
Compute every power a^b for a, b in [2..N] and count distinct
values. Hashtbl as a set with unit-payload (iter-168 idiom):
let euler29 n =
let h = Hashtbl.create 64 in
for a = 2 to n do
for b = 2 to n do
let p = ref 1 in
for _ = 1 to b do p := !p * a done;
Hashtbl.replace h !p ()
done
done;
Hashtbl.length h
For N=5: 16 powers minus one duplicate (4^2 = 2^4 = 16) -> 15.
Real PE29 uses N=100 (answer 9183).
120 baseline programs total — milestone.
This commit is contained in:
14
lib/ocaml/baseline/euler29_small.ml
Normal file
14
lib/ocaml/baseline/euler29_small.ml
Normal file
@@ -0,0 +1,14 @@
|
||||
let euler29 n =
|
||||
let h = Hashtbl.create 64 in
|
||||
for a = 2 to n do
|
||||
for b = 2 to n do
|
||||
let p = ref 1 in
|
||||
for _ = 1 to b do p := !p * a done;
|
||||
Hashtbl.replace h !p ()
|
||||
done
|
||||
done;
|
||||
Hashtbl.length h
|
||||
|
||||
;;
|
||||
|
||||
euler29 5
|
||||
@@ -33,6 +33,7 @@
|
||||
"euler21_small.ml": 504,
|
||||
"euler25.ml": 55,
|
||||
"euler28.ml": 261,
|
||||
"euler29_small.ml": 15,
|
||||
"euler30_cube.ml": 1301,
|
||||
"euler3.ml": 29,
|
||||
"euler4_small.ml": 9009,
|
||||
|
||||
@@ -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 — euler29_small.ml baseline (distinct a^b for
|
||||
2≤a,b≤5 = 15). 16 powers minus the one duplicate (4^2 = 2^4 = 16)
|
||||
→ 15 distinct values. Hashtbl as a set with unit-payload (the
|
||||
iter-168 idiom). Real PE29 uses N=100 (answer 9183). 120 baseline
|
||||
programs total — milestone.
|
||||
- 2026-05-09 Phase 5.1 — euler21_small.ml baseline (sum of amicable
|
||||
numbers ≤ 300 = 504). div_sum computes proper divisor sum via
|
||||
trial division up to √n; outer loop finds amicable pairs (a, b)
|
||||
|
||||
Reference in New Issue
Block a user