ocaml: phase 5.1 euler34_small.ml baseline (factorions <= 2000 = 145)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

Number that equals the sum of factorials of its digits:
  145 = 1! + 4! + 5! = 1 + 24 + 120

Implementation:
  fact n           iterative factorial
  digit_fact_sum n walk digits, sum fact(digit)
  euler34 limit    scan 3..limit, accumulate matches

The only other factorion is 40585 = 4!+0!+5!+8!+5!. Real PE34 sums
both (= 40730); 2000 keeps under our search budget.

121 baseline programs total.
This commit is contained in:
2026-05-09 23:50:25 +00:00
parent 21dbd195d5
commit 4e6a345342
3 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
let fact n =
let r = ref 1 in
for i = 2 to n do r := !r * i done;
!r
let digit_fact_sum n =
let m = ref n in
let s = ref 0 in
while !m > 0 do
s := !s + fact (!m mod 10);
m := !m / 10
done;
!s
let euler34 limit =
let total = ref 0 in
for n = 3 to limit do
if digit_fact_sum n = n then total := !total + n
done;
!total
;;
euler34 2000

View File

@@ -35,6 +35,7 @@
"euler28.ml": 261,
"euler29_small.ml": 15,
"euler30_cube.ml": 1301,
"euler34_small.ml": 145,
"euler3.ml": 29,
"euler4_small.ml": 9009,
"euler5.ml": 232792560,