From b8d51613cbf4d730e62425abcb555583612ed677 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Fri, 3 Dec 2021 08:12:08 +0000 Subject: ch1 soln --- challenge-141/james-smith/perl/ch-1.pl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 challenge-141/james-smith/perl/ch-1.pl 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]; + -- cgit