Advertisement
Guest User

CoPrimes

a guest
Oct 21st, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let (|LT|EQ|GT|) (x, y) =
  2.   if x < y then LT
  3.   elif x = y then EQ
  4.   else GT
  5.  
  6. let areCoPrimes x y =
  7.   let rec aux (x, y) =
  8.     match x, y with
  9.     | 0, _ | _, 0 -> false
  10.     | LT          -> aux (x, y - x)
  11.     | EQ          -> x = 1
  12.     | GT          -> aux (x - y, y)
  13.   aux (abs x, abs y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement