diff --git a/31.ml b/31.ml new file mode 100644 index 0000000..2e1e704 --- /dev/null +++ b/31.ml @@ -0,0 +1,18 @@ +(* Determine whether two positive integer numbers are coprime. (easy) + +Two numbers are coprime if their greatest common divisor equals 1. *) +(* + # coprime 13 27;; + - : bool = true + # not (coprime 20536 7826);; + - : bool = true +*) + +let coprime a b = + let rec gcd a = function + | 0 -> a + | b -> gcd b (a mod b) in + (gcd a b) = 1;; + +coprime 13 27;; +coprime 20536 7826;; \ No newline at end of file