aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-05-04 13:53:02 +0200
committerAbigail <abigail@abigail.be>2021-05-04 13:53:02 +0200
commitb90ff173699409bb267dca8f122034c8a1572df7 (patch)
tree2ec24193ab71604ac3b8622307d437b60dd07ccc
parentc8bdf59902b53b33005f98d3538fcf57329bf7c8 (diff)
downloadperlweeklychallenge-club-b90ff173699409bb267dca8f122034c8a1572df7.tar.gz
perlweeklychallenge-club-b90ff173699409bb267dca8f122034c8a1572df7.tar.bz2
perlweeklychallenge-club-b90ff173699409bb267dca8f122034c8a1572df7.zip
AWK solution for week 111, part 1
-rw-r--r--challenge-111/abigail/README.md1
-rw-r--r--challenge-111/abigail/awk/ch-1.awk30
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md
index c72b062759..ce06c3891c 100644
--- a/challenge-111/abigail/README.md
+++ b/challenge-111/abigail/README.md
@@ -31,6 +31,7 @@ make use of the fact the input is sorted. For the majority of
languages, the fact input is sorted does not offer additional benefits.
### Solutions
+* [AWK](awk/ch-1.awk)
* [Perl](perl/ch-1.pl)
### Blog
diff --git a/challenge-111/abigail/awk/ch-1.awk b/challenge-111/abigail/awk/ch-1.awk
new file mode 100644
index 0000000000..c82c027708
--- /dev/null
+++ b/challenge-111/abigail/awk/ch-1.awk
@@ -0,0 +1,30 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-1.awk < input-file
+#
+
+BEGIN {
+ MATRIX_SIZE = 5
+}
+
+#
+# Read in the matrix first
+#
+NR <= MATRIX_SIZE {
+ for (i = 1; i <= NF; i ++) {
+ matrix [$i] = 1
+ }
+}
+
+#
+# For the rest, print 1/0 depending on whether the input
+# is in the matrix or not.
+#
+NR > MATRIX_SIZE {
+ print (matrix [$0] ? 1 : 0)
+}