summaryrefslogtreecommitdiff
path: root/gcd.sh
diff options
context:
space:
mode:
authorIgor <pashev.igor@gmail.com>2011-01-22 18:09:37 +0300
committerIgor <pashev.igor@gmail.com>2011-01-22 18:09:37 +0300
commit9e677082cfd5af8d0ac76672784cc00ecaa3ed1a (patch)
treed55bdf645d5a2e7f62c472e0a33a0d1436788019 /gcd.sh
parent0475936b4046273a34249b4337629c4ab82f1683 (diff)
downloadgcd-9e677082cfd5af8d0ac76672784cc00ecaa3ed1a.tar.gz
Shell
Diffstat (limited to 'gcd.sh')
-rwxr-xr-xgcd.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/gcd.sh b/gcd.sh
new file mode 100755
index 0000000..9548b1d
--- /dev/null
+++ b/gcd.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+gcd2() {
+ if test $2 = 0 ; then
+ echo $1
+ else
+ gcd2 $2 `expr $1 % $2`
+ fi
+}
+
+gcdn() {
+ r=$1; shift
+ for n in $*; do
+ r=`gcd2 $r $n`
+ done
+ echo $r
+}
+
+gcdn $*
+