summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-07-09 10:02:13 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-07-09 10:02:13 +0300
commit9f86fb4b7d33e07ec2455dd5dcc0de07b5aad495 (patch)
tree532f62c006995a13981a030eb6f6dc264e46f664
parent24ad026f3525f806f5fb8eaf1367c2b160d32490 (diff)
downloadgcd-9f86fb4b7d33e07ec2455dd5dcc0de07b5aad495.tar.gz
Update Haskell
-rw-r--r--gcd.hs26
1 files changed, 21 insertions, 5 deletions
diff --git a/gcd.hs b/gcd.hs
index fe07fc0..b044c85 100644
--- a/gcd.hs
+++ b/gcd.hs
@@ -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)