From 53968c24800f674644d48a8ac0b5c1050e115431 Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 9 May 2026 19:56:58 +0000 Subject: [PATCH] ocaml: phase 5.1 euler1.ml baseline (Project Euler #1, multiples of 3 or 5 below 1000 = 233168) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Project Euler #1: sum of all multiples of 3 or 5 below 1000. let euler1 limit = let sum = ref 0 in for i = 1 to limit - 1 do if i mod 3 = 0 || i mod 5 = 0 then sum := !sum + i done; !sum euler1 1000 = 233168 Trivial DSL exercise but symbolically meaningful: this is the 100th baseline program. 100 baseline programs total — milestone. --- lib/ocaml/baseline/euler1.ml | 10 ++++++++++ lib/ocaml/baseline/expected.json | 1 + plans/ocaml-on-sx.md | 3 +++ 3 files changed, 14 insertions(+) create mode 100644 lib/ocaml/baseline/euler1.ml diff --git a/lib/ocaml/baseline/euler1.ml b/lib/ocaml/baseline/euler1.ml new file mode 100644 index 00000000..42cb2d01 --- /dev/null +++ b/lib/ocaml/baseline/euler1.ml @@ -0,0 +1,10 @@ +let euler1 limit = + let sum = ref 0 in + for i = 1 to limit - 1 do + if i mod 3 = 0 || i mod 5 = 0 then sum := !sum + i + done; + !sum + +;; + +euler1 1000 diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index bc8170b1..dd452b56 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -24,6 +24,7 @@ "csv.ml": 10, "exception_handle.ml": 4, "exception_user.ml": 26, + "euler1.ml": 233168, "expr_eval.ml": 16, "expr_simp.ml": 22, "factorial.ml": 3628800, diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 3c78bdef..66b49f0d 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,9 @@ _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 — euler1.ml baseline (Project Euler #1, sum + of multiples of 3 or 5 below 1000 = 233168). Trivial DSL exercise + but symbolically meaningful: this is the 100th baseline program. - 2026-05-09 Phase 5.1 — anagram_groups.ml baseline (group strings by canonical anagram form, ["eat";"tea";"tan";"ate";"nat";"bat"] has 3 groups). canonical builds a sorted-by-frequency string