aboutsummaryrefslogtreecommitdiff
path: root/challenge-089/ash/bash
diff options
context:
space:
mode:
authorAndrew Shitov <andy@shitov.ru>2020-12-04 09:17:37 +0100
committerAndrew Shitov <andy@shitov.ru>2020-12-04 09:17:37 +0100
commitfdd800775ca52e7600d78f38e5345a5197cc086c (patch)
tree83e6da7d9535c716d29a57bab98f2a91cdcf4994 /challenge-089/ash/bash
parentd19b0f983bbefca06f6139624711c079ac18eb6e (diff)
downloadperlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.tar.gz
perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.tar.bz2
perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.zip
Week 89 Issue 1
Diffstat (limited to 'challenge-089/ash/bash')
-rw-r--r--challenge-089/ash/bash/ch-1.bash37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-089/ash/bash/ch-1.bash b/challenge-089/ash/bash/ch-1.bash
new file mode 100644
index 0000000000..cb3cd93dbb
--- /dev/null
+++ b/challenge-089/ash/bash/ch-1.bash
@@ -0,0 +1,37 @@
+#!/usr/bin/bash
+
+# Usage:
+# $ bash ch-1.bash 100
+# 13015
+#
+# N. B. Try with smaller arguments, as computations
+# for the input number of 100 can take a while (~ a minute).
+
+gcd() {
+ a=$1;
+ b=$2;
+ while [ $b -ne 0 ]; do
+ t=$b
+ b=`expr $a % $b`
+ a=$t
+ done
+
+ gcd=$a
+}
+
+n=${1:-3} # default is 3
+
+s=0
+x=1
+while [ $x -le $n ]; do
+ next=`expr $x + 1`;
+ y=$next;
+ while [ $y -le $n ]; do
+ y=`expr $y + 1`;
+ gcd $x $y;
+ s=`expr $s + $gcd`;
+ done
+ x=$next;
+done
+
+echo $s