diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 03ab6707..e338cc68 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -105,6 +105,7 @@ "poly_stack.ml": 5, "pow_mod.ml": 738639, "prime_factors.ml": 17, + "pythagorean.ml": 16, "queens.ml": 2, "quicksort.ml": 44, "roman.ml": 44, diff --git a/lib/ocaml/baseline/pythagorean.ml b/lib/ocaml/baseline/pythagorean.ml new file mode 100644 index 00000000..3710c0c2 --- /dev/null +++ b/lib/ocaml/baseline/pythagorean.ml @@ -0,0 +1,19 @@ +let rec gcd a b = if b = 0 then a else gcd b (a mod b) + +let count_primitive_triples n = + let c = ref 0 in + for m = 2 to 50 do + let kk = ref 1 in + while !kk < m do + if (m - !kk) mod 2 = 1 && gcd m !kk = 1 then begin + let h = m * m + !kk * !kk in + if h <= n then c := !c + 1 + end; + kk := !kk + 1 + done + done; + !c + +;; + +count_primitive_triples 100 diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index e121528e..ef2b5f7b 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-10 Phase 5.1 — pythagorean.ml baseline (count primitive + Pythagorean triples with hypotenuse ≤ 100 = 16). Uses Euclid's + formula: for coprime m > k of opposite parity, the triple + (m² - k², 2mk, m² + k²) is primitive Pythagorean. The 16 triples + are (3,4,5), (5,12,13), (8,15,17), (7,24,25), (20,21,29), + (9,40,41), ..., (65,72,97). 134 baseline programs total. - 2026-05-10 Phase 5.1 — harshad.ml baseline (count Niven/Harshad numbers ≤ 100 = 33). A Harshad number is divisible by its digit sum. All single-digit numbers qualify trivially (9). Plus 10, 12,