diff --git a/lib/ocaml/baseline/euler34_small.ml b/lib/ocaml/baseline/euler34_small.ml new file mode 100644 index 00000000..b8725b9a --- /dev/null +++ b/lib/ocaml/baseline/euler34_small.ml @@ -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 diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 5255b53d..d0b59c2f 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -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, diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index afec331a..01a85248 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -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 — euler34_small.ml baseline (numbers equal + to sum of factorials of digits, ≤2000 = 145). 145 = 1!+4!+5! = + 1+24+120. The other "factorion" 40585 is the only number above + this threshold; PE34 sums both = 40730. 121 baseline programs + total. - 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