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,
|
||||
|
||||
Reference in New Issue
Block a user