diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-10-07 09:24:59 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-10-07 09:24:59 +0100 |
| commit | 6e73c23e763f18f3d7e3eb039ca3648814ac8afa (patch) | |
| tree | 310caf9a3fa002c8db5b1c33535c3938fab085b2 | |
| parent | a4e10603fb553c91e50c77349a6f5d46b1cdceba (diff) | |
| download | perlweeklychallenge-club-6e73c23e763f18f3d7e3eb039ca3648814ac8afa.tar.gz perlweeklychallenge-club-6e73c23e763f18f3d7e3eb039ca3648814ac8afa.tar.bz2 perlweeklychallenge-club-6e73c23e763f18f3d7e3eb039ca3648814ac8afa.zip | |
add code so dont't try primes greater than root n
| -rw-r--r-- | challenge-133/james-smith/perl/ch-2.pl | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/challenge-133/james-smith/perl/ch-2.pl b/challenge-133/james-smith/perl/ch-2.pl index 24616a3b82..053d890468 100644 --- a/challenge-133/james-smith/perl/ch-2.pl +++ b/challenge-133/james-smith/perl/ch-2.pl @@ -16,7 +16,7 @@ sub sum_prime_factors { my $N = shift; ## If we are composite then store the sum of the digit factors for the composite and return... - ( $N % $_) || ( return $sum_pf[$N] = $sum_pf[$N/$_] + $sum_pf[$_] ) + ( $N % $_) ? (( $N<$_*$_) && last ) : ( return $sum_pf[$N] = $sum_pf[$N/$_] + $sum_pf[$_] ) foreach @primes; ## Otherwise we are prime so add to primes and return nothing.... |
