aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/abigail/awk/ch-2.awk
blob: 6353b61eb8d0fb97bcec60b0cf01e242d1228c2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/awk

#
# See ../README.md
#

#
# Run as: awk -f ch-2.awk < input-file
#

{
    sum_of_squares = 0
    for (i = 1; i <= length ($1); i ++) {
        # Sum of squares
        sum_of_squares += substr ($1, i, 1) * substr ($1, i, 1)
    }
    root = int (.5 + int (sqrt (sum_of_squares)))
    print (sum_of_squares == root * root ? 1 : 0)
}