diff options
| author | Abigail <abigail@abigail.be> | 2021-01-27 20:43:02 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-27 20:43:02 +0100 |
| commit | 9826be5b0b81a3c95ebaa70216b204ac055d1c2a (patch) | |
| tree | 41a071790f4711e9f80843ab81bf7be0a36d9bf5 | |
| parent | 8a6c1f8f1cc9d8bf0e6b83769f5911a3e3792544 (diff) | |
| download | perlweeklychallenge-club-9826be5b0b81a3c95ebaa70216b204ac055d1c2a.tar.gz perlweeklychallenge-club-9826be5b0b81a3c95ebaa70216b204ac055d1c2a.tar.bz2 perlweeklychallenge-club-9826be5b0b81a3c95ebaa70216b204ac055d1c2a.zip | |
AWK solution for week 3, part 1
| -rw-r--r-- | challenge-003/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-003/abigail/awk/ch-1.awk | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index f3769f3939..1b9e794af2 100644 --- a/challenge-003/abigail/README.md +++ b/challenge-003/abigail/README.md @@ -8,6 +8,7 @@ numbers. For more information, please check this ### Solutions +* [AWK](awk/ch-1.awk) * [Perl](perl/ch-1.pl) diff --git a/challenge-003/abigail/awk/ch-1.awk b/challenge-003/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..706014ed91 --- /dev/null +++ b/challenge-003/abigail/awk/ch-1.awk @@ -0,0 +1,29 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk < input-file +# + +# +# Generate the 5-smooth numbers up to $0. +# This does *NOT* generate the numbers is order. It does, however, +# generate all of them, and no other numbers. +# +# +# base2 is of the form 2^i; i >= 0 +# base3 if of the form 2^i * 3^j; i, j >= 0 +# base5 is of the form 2^i * 3^j * 5^k; i, j, k >= 0 +# +{ + for (base2 = 1; base2 <= $0; base2 *= 2) { + for (base3 = base2; base3 <= $0; base3 *= 3) { + for (base5 = base3; base5 <= $0; base5 *= 5) { + print base5 + } + } + } +} |
