summaryrefslogtreecommitdiff
path: root/gcd.hs
diff options
context:
space:
mode:
authorIgor <pashev.igor@gmail.com>2011-01-12 15:33:44 +0300
committerIgor <pashev.igor@gmail.com>2011-01-12 15:33:44 +0300
commitcb9ab4e10b97f91bcf78fc643821851097a54e7e (patch)
treeac08985c2e405a77d7599f0934561cb6acdbd603 /gcd.hs
downloadgcd-cb9ab4e10b97f91bcf78fc643821851097a54e7e.tar.gz
Begin: C, C#, Haskell, Java, Python
Diffstat (limited to 'gcd.hs')
-rw-r--r--gcd.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/gcd.hs b/gcd.hs
new file mode 100644
index 0000000..c326115
--- /dev/null
+++ b/gcd.hs
@@ -0,0 +1,14 @@
+import System(getArgs)
+
+gcd2 a 0 = a
+gcd2 a b = gcd2 b (rem b a)
+
+gcdn n = foldl1 gcd2 n
+
+str2int :: String -> Integer
+str2int = read
+
+main = do
+ a <- getArgs
+ print (gcdn (map str2int a))
+