Skip to content

Instantly share code, notes, and snippets.

@AHaliq
Created August 13, 2021 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AHaliq/4f768d3579963daaa93da16fb45112cf to your computer and use it in GitHub Desktop.
Save AHaliq/4f768d3579963daaa93da16fb45112cf to your computer and use it in GitHub Desktop.
Haskell Euclid Algorithm
euclid :: Integer -> Integer -> Integer
euclid a b = case aux a b 0 of
0 -> b
r -> euclid b r
where
aux a b q = if b >= a then b - a else aux (a-b) b (q+1)
-- get gcd
main = do
a <- readLn :: IO Integer
b <- readLn :: IO Integer
 putStrLn $ show $ euclid a b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment