diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-06-15 00:19:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-15 00:19:55 +0100 |
| commit | 4265fcec64f789351275f3766c7b9d2e2f931e82 (patch) | |
| tree | 0b846061c5c535282ce40e4ac42d36b46a27c018 | |
| parent | 3a6c5bb04db16be0d61eeac0d74488966d6ba2f4 (diff) | |
| parent | 5e2b01048367e65eb486a9ac4b83cf2541fb2a79 (diff) | |
| download | perlweeklychallenge-club-4265fcec64f789351275f3766c7b9d2e2f931e82.tar.gz perlweeklychallenge-club-4265fcec64f789351275f3766c7b9d2e2f931e82.tar.bz2 perlweeklychallenge-club-4265fcec64f789351275f3766c7b9d2e2f931e82.zip | |
Merge pull request #6267 from choroba/ech169
Solve 169: Brilliant Numbers & Achilles Numbers by E. Choroba
| -rwxr-xr-x | challenge-169/e-choroba/perl/ch-1.pl | 24 | ||||
| -rwxr-xr-x | challenge-169/e-choroba/perl/ch-2.pl | 25 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-169/e-choroba/perl/ch-1.pl b/challenge-169/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..ef863b1cbc --- /dev/null +++ b/challenge-169/e-choroba/perl/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use Math::Prime::Util qw{ factor }; + +sub brilliant_numbers { + my ($tally) = @_; + my @brilliant_numbers; + my $n = 1; + while (@brilliant_numbers < $tally) { + my @f = factor(++$n); + push @brilliant_numbers, $n + if 2 == @f + && length($f[0]) == length($f[1]); + } + return \@brilliant_numbers +} + +use Test::More tests => 1; + +is_deeply brilliant_numbers(20), + [4, 6, 9, 10, 14, 15, 21, 25, 35, 49, 121, + 143, 169, 187, 209, 221, 247, 253, 289, 299]; diff --git a/challenge-169/e-choroba/perl/ch-2.pl b/challenge-169/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..48e9f7c4eb --- /dev/null +++ b/challenge-169/e-choroba/perl/ch-2.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use Math::Prime::Util qw{ factor gcd }; + +sub achilles_numbers { + my ($tally) = @_; + my $n = 1; + my @achilles_numbers; + while (@achilles_numbers < $tally) { + my %factors; + ++$factors{$_} for factor(++$n); + next if grep $_ == 1, values %factors; # Powerful. + + push @achilles_numbers, $n + if 1 == gcd(values %factors); # Not perfect. + } + return \@achilles_numbers +} + +use Test::More tests => 1; +is_deeply achilles_numbers(20), + [72, 108, 200, 288, 392, 432, 500, 648, 675, 800, 864, + 968, 972, 1125, 1152, 1323, 1352, 1372, 1568, 1800]; |
