aboutsummaryrefslogtreecommitdiff
path: root/challenge-003/abigail/awk
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-01-28 01:58:14 +0100
committerAbigail <abigail@abigail.be>2021-01-28 02:22:08 +0100
commit94066ce3eb7bbfcf7da711e6e9f703df791a48de (patch)
treee6b5e06de24b15099dd82ec1b8813cd20fe77a49 /challenge-003/abigail/awk
parent58450e134351ade0f649cc27befe6931741c2c56 (diff)
downloadperlweeklychallenge-club-94066ce3eb7bbfcf7da711e6e9f703df791a48de.tar.gz
perlweeklychallenge-club-94066ce3eb7bbfcf7da711e6e9f703df791a48de.tar.bz2
perlweeklychallenge-club-94066ce3eb7bbfcf7da711e6e9f703df791a48de.zip
AWK solution for week 3, part 2
Diffstat (limited to 'challenge-003/abigail/awk')
-rw-r--r--challenge-003/abigail/awk/ch-2.awk33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-003/abigail/awk/ch-2.awk b/challenge-003/abigail/awk/ch-2.awk
new file mode 100644
index 0000000000..1689ce668f
--- /dev/null
+++ b/challenge-003/abigail/awk/ch-2.awk
@@ -0,0 +1,33 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-2.awk < input-file
+#
+
+{
+ row [1] = 1 # 0'th row
+ printf "%d\n", row [1]
+
+ for (r = 1; r <= $0; r ++) {
+ #
+ # Calculate the new row, and print it
+ #
+ for (i = 1; i <= length (row) + 1; i ++) {
+ new [i] = (i == 1 ? 0 : row [i - 1]) +\
+ (i == length (row) + 1 ? 0 : row [i])
+ printf ("%s%d", i == 1 ? "" : " ", new [i])
+ }
+ printf "\n";
+
+ #
+ # Copy the new row to the current row
+ #
+ for (i = 1; i <= length (new); i ++) {
+ row [i] = new [i]
+ }
+ }
+}