diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2017-07-09 10:02:13 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-07-09 10:02:13 +0300 |
commit | 9f86fb4b7d33e07ec2455dd5dcc0de07b5aad495 (patch) | |
tree | 532f62c006995a13981a030eb6f6dc264e46f664 | |
parent | 24ad026f3525f806f5fb8eaf1367c2b160d32490 (diff) | |
download | gcd-9f86fb4b7d33e07ec2455dd5dcc0de07b5aad495.tar.gz |
Update Haskell
-rw-r--r-- | gcd.hs | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -1,14 +1,30 @@ -import System.Environment(getArgs) +{- +Usage: + + $ runhaskell gcd.hs 22 11 + 11 + +or: + + $ ghc gcd.hs -o gcd-hs + $ ./gcd-hs 11 22 121 + 11 + +-} +import System.Environment (getArgs) + +gcd2 :: Integer -> Integer -> Integer gcd2 a 0 = a gcd2 a b = gcd2 b (a `rem` b) -gcdn n = foldl1 gcd2 n +gcdn :: [Integer] -> Integer +gcdn = foldl1 gcd2 str2int :: String -> Integer str2int = read +main :: IO () main = do - a <- getArgs - print (gcdn (map str2int a)) - + a <- getArgs + print $ gcdn (map str2int a) |