Created
August 13, 2021 10:14
-
-
Save AHaliq/4f768d3579963daaa93da16fb45112cf to your computer and use it in GitHub Desktop.
Haskell Euclid Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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