aboutsummaryrefslogtreecommitdiff
path: root/challenge-111/abigail/awk/ch-1.awk
blob: c82c027708af072fc15fc66361d671896cbfe4c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)
}