ocaml: phase 5.1 gcd_lcm.ml baseline (Euclidean gcd + lcm, 12+12+36 = 60)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 19s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 19s
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.
This commit is contained in:
@@ -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,
|
||||
|
||||
6
lib/ocaml/baseline/gcd_lcm.ml
Normal file
6
lib/ocaml/baseline/gcd_lcm.ml
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user