diff options
| -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 + } + } + } +} |
