diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 2f291158..140edeea 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -20,6 +20,7 @@ "factorial.ml": 3628800, "fraction.ml": 7, "frequency.ml": 5, + "gcd_lcm.ml": 60, "grep_count.ml": 3, "hanoi.ml": 1023, "fizzbuzz.ml": 57, diff --git a/lib/ocaml/baseline/gcd_lcm.ml b/lib/ocaml/baseline/gcd_lcm.ml new file mode 100644 index 00000000..5b958db0 --- /dev/null +++ b/lib/ocaml/baseline/gcd_lcm.ml @@ -0,0 +1,6 @@ +let rec gcd a b = if b = 0 then a else gcd b (a mod b) + +let lcm a b = a * b / gcd a b +;; + +gcd 36 48 + lcm 4 6 + lcm 12 18 diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 82eee160..377f0165 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,12 @@ _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 — gcd_lcm.ml baseline (Euclidean gcd + lcm, + 12 + 12 + 36 = 60). Two-line baseline: `let rec gcd a b = if b = 0 + then a else gcd b (a mod b)` + `let lcm a b = a * b / gcd a b`. + Tests `mod` arithmetic and the integer-division fix from + iteration 94 (without truncate-toward-zero, lcm 4 6 = 4*6 / 2 = + 12.0 not 12). 54 baseline programs total. - 2026-05-09 Phase 5.1 — zip_unzip.ml baseline (list zip/unzip round-trip, sum-product = 1000). zip walks both lists in lockstep truncating at the shorter; unzip uses tuple-pattern destructuring