diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-12-03 08:12:08 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-12-03 08:12:08 +0000 |
| commit | b8d51613cbf4d730e62425abcb555583612ed677 (patch) | |
| tree | c1a8c59fb7d82a7439cb52107b20a1847c78ac34 | |
| parent | fb0b052f476665a5378dc85348fe987f50267cc7 (diff) | |
| download | perlweeklychallenge-club-b8d51613cbf4d730e62425abcb555583612ed677.tar.gz perlweeklychallenge-club-b8d51613cbf4d730e62425abcb555583612ed677.tar.bz2 perlweeklychallenge-club-b8d51613cbf4d730e62425abcb555583612ed677.zip | |
ch1 soln
| -rw-r--r-- | challenge-141/james-smith/perl/ch-1.pl | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-141/james-smith/perl/ch-1.pl b/challenge-141/james-smith/perl/ch-1.pl new file mode 100644 index 0000000000..69282db686 --- /dev/null +++ b/challenge-141/james-smith/perl/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/local/bin/perl + +use strict; + +use warnings; +use feature qw(say); +use Test::More; +use Benchmark qw(cmpthese timethis); +use Data::Dumper qw(Dumper); + +my @primes = (2,3,5,7,11,13); +my @vals; + +## +## We know that all such numbers must have the form: +## p^3.q, p.q.r +## where p, q, r are all primes... +## +## We therefore constuct all such combinations of the primes <= 13 +## this should include the 10 numbers we are looking for! + +while(@primes) { + my $p1 = shift @primes; + my @t = @primes; + while( @t ) { + my $p2 = shift @t; + push @vals, $p1*$p2*$p2*$p2, $p2*$p1*$p1*$p1, map {$p1*$p2*$_} @t; + } +} + +say join "\n",(sort{$a<=>$b}@vals)[0..9]; + |
