aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-141/james-smith/perl/ch-1.pl8
-rw-r--r--challenge-141/james-smith/perl/ch-2.pl10
2 files changed, 8 insertions, 10 deletions
diff --git a/challenge-141/james-smith/perl/ch-1.pl b/challenge-141/james-smith/perl/ch-1.pl
index 69282db686..5ee8bbe11b 100644
--- a/challenge-141/james-smith/perl/ch-1.pl
+++ b/challenge-141/james-smith/perl/ch-1.pl
@@ -13,20 +13,20 @@ my @vals;
##
## We know that all such numbers must have the form:
-## p^3.q, p.q.r
+## p^8, 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;
+ push @vals,(my $p1 = shift @primes)**8;
my @t = @primes;
while( @t ) {
my $p2 = shift @t;
- push @vals, $p1*$p2*$p2*$p2, $p2*$p1*$p1*$p1, map {$p1*$p2*$_} @t;
+ push @vals, $p1*$p2**3, $p2*$p1**3, map {$p1*$p2*$_} @t;
}
}
-say join "\n",(sort{$a<=>$b}@vals)[0..9];
+say for (sort{$a<=>$b}@vals)[0..9];
diff --git a/challenge-141/james-smith/perl/ch-2.pl b/challenge-141/james-smith/perl/ch-2.pl
index 5e4af7babb..8ff4a87996 100644
--- a/challenge-141/james-smith/perl/ch-2.pl
+++ b/challenge-141/james-smith/perl/ch-2.pl
@@ -18,11 +18,9 @@ is( like_numbers(@{$_->[0]}), $_->[1] ) foreach @TESTS;
done_testing();
sub like_numbers {
- scalar grep { !($_%$_[1]) } get_nums( $_[0] );
-}
-
-sub get_nums {
- my @nums = split //, my $m = shift;
- return map { my $n=$_<<1; join '',grep{($n>>=1)&1} @nums } 1..(1<<@nums)-2;
+ my @digits = split//,$_[0];
+ 0 + grep { !($_%$_[1]) }
+ map { my $n=$_<<1; join '',grep{($n>>=1)&1} @digits }
+ 1 .. (1<<@digits) - 2;
}