aboutsummaryrefslogtreecommitdiff
path: root/challenge-141/abigail/awk/ch-1.awk
blob: 9b9ae8dc67b6b1565029f5d7cd0ca625b0cdf6b1 (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
31
#!/usr/bin/awk

#
# See ../README.md
#

#
# Run as: awk -f ch-1.awk
#

BEGIN {
    count          = 10;
    nr_of_divisors =  8;

    for (n = 1; count > 0; n ++) {
        s = int sqrt (n);
        if (n == s * s) {
            continue
        }
        c = 0;
        for (m = 1; m <= s && c <= nr_of_divisors; m ++) {
            if (n % m == 0) {
                c += 2
            }
        }
        if (c == nr_of_divisors) {
            print (n)
            count --
        }
    }
}