aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.freedom.nl>2022-01-06 13:56:30 +0100
committerAbigail <abigail@abigail.freedom.nl>2022-01-06 13:56:30 +0100
commit76e71dbba093a8fa883b945df09e22d4b5b94ae2 (patch)
treef98b9e9fd1cedc5bcf39df7c41577661b653af31
parente22456cd4100b9d24449a0a1623236f0b5ecb412 (diff)
downloadperlweeklychallenge-club-76e71dbba093a8fa883b945df09e22d4b5b94ae2.tar.gz
perlweeklychallenge-club-76e71dbba093a8fa883b945df09e22d4b5b94ae2.tar.bz2
perlweeklychallenge-club-76e71dbba093a8fa883b945df09e22d4b5b94ae2.zip
Week 3, part 2: bash solution
-rw-r--r--challenge-003/abigail/bash/ch-2.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-003/abigail/bash/ch-2.sh b/challenge-003/abigail/bash/ch-2.sh
new file mode 100644
index 0000000000..ca5e5fb510
--- /dev/null
+++ b/challenge-003/abigail/bash/ch-2.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003
+#
+
+#
+# Run as: bash ch-2.sh < input-file
+#
+
+set -f
+
+declare -A p
+
+while read n
+do for ((row = 0; row <= n; row ++))
+ do p["$row;0"]=1
+ printf "1 "
+ for ((col = 1; col <= row; col ++))
+ do p["$row;$col"]=$((${p["$((row-1));$((col-1))"]:-0} + \
+ ${p["$((row-1));$col"]:-0}))
+ printf "%d " ${p["$row;$col"]}
+ done
+ echo
+ done
+done