diff options
| -rw-r--r-- | challenge-111/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-111/abigail/awk/ch-1.awk | 30 |
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) +} |
