From 8a6c1f8f1cc9d8bf0e6b83769f5911a3e3792544 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 27 Jan 2021 20:35:48 +0100 Subject: Perl solution for week 3, part 1 --- challenge-003/abigail/README.md | 1 + challenge-003/abigail/perl/ch-1.pl | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 challenge-003/abigail/perl/ch-1.pl 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; + } + } +} -- cgit