csci2041/public-class-repo/SamplePrograms/gcd.ml

9 lines
197 B
OCaml
Raw Normal View History

2018-01-29 23:35:31 +00:00
let gcd m n =
let smallest = if m < n then m else n
in
let rec helper guess =
if m mod guess = 0 && n mod guess = 0 then guess
else helper (guess - 1)
in helper smallest