summaryrefslogtreecommitdiff
path: root/gcd.py
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.py
downloadgcd-cb9ab4e10b97f91bcf78fc643821851097a54e7e.tar.gz
Begin: C, C#, Haskell, Java, Python
Diffstat (limited to 'gcd.py')
-rwxr-xr-xgcd.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/gcd.py b/gcd.py
new file mode 100755
index 0000000..d6774a0
--- /dev/null
+++ b/gcd.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3
+
+import sys
+import functools
+
+def gcd2(a, b):
+ if b == 0:
+ return a
+ else:
+ return gcd2(b, a % b)
+
+def gcdn(ns):
+ return functools.reduce(gcd2, ns)
+
+ints = map(int, sys.argv[1:])
+gcd = gcdn(ints)
+print(gcd)
+