diff options
| author | Abigail <abigail@abigail.be> | 2021-01-27 20:35:48 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-27 20:35:48 +0100 |
| commit | 8a6c1f8f1cc9d8bf0e6b83769f5911a3e3792544 (patch) | |
| tree | 5bfc47402139fb810393fb0230fa7da64c76704e | |
| parent | 0b2635ec6cfe8f8605c9492c924b8619e3d6eb3c (diff) | |
| download | perlweeklychallenge-club-8a6c1f8f1cc9d8bf0e6b83769f5911a3e3792544.tar.gz perlweeklychallenge-club-8a6c1f8f1cc9d8bf0e6b83769f5911a3e3792544.tar.bz2 perlweeklychallenge-club-8a6c1f8f1cc9d8bf0e6b83769f5911a3e3792544.zip | |
Perl solution for week 3, part 1
| -rw-r--r-- | challenge-003/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-003/abigail/perl/ch-1.pl | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index 87eff47adc..f3769f3939 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 +* [Perl](perl/ch-1.pl) ## [Challenge #2](https://perlweeklychallenge.org/blog/perl-weekly-challenge-003/#challenge-2) diff --git a/challenge-003/abigail/perl/ch-1.pl b/challenge-003/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..352466e41c --- /dev/null +++ b/challenge-003/abigail/perl/ch-1.pl @@ -0,0 +1,41 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See ../README.md +# + +# +# Run as: perl ch-1.pl < input-file +# + +# +# Read the maximum number from STDIN +# +chomp (my $MAX = <>); + +# +# Generate the 5-smooth numbers up to $MAX. +# 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 (my $base2 = 1; $base2 <= $MAX; $base2 *= 2) { + for (my $base3 = $base2; $base3 <= $MAX; $base3 *= 3) { + for (my $base5 = $base3; $base5 <= $MAX; $base5 *= 5) { + say $base5; + } + } +} |
