Files
rose-ash/lib/ocaml/baseline/gcd_lcm.ml
giles cca3a28206
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 19s
ocaml: 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

  gcd 36 48  = 12
  lcm 4 6    = 12
  lcm 12 18  = 36
  sum        = 60

Tests mod arithmetic and the integer-division fix from iteration 94
(without truncate-toward-zero, 'lcm 4 6 = 4 * 6 / 2 = 12.0' rather
than the expected 12).

54 baseline programs total.
2026-05-09 11:42:52 +00:00

7 lines
122 B
OCaml

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