aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordcw <d.white@imperial.ac.uk>2022-06-19 21:19:30 +0100
committerdcw <d.white@imperial.ac.uk>2022-06-19 21:19:30 +0100
commit658e60b76deb452bf572385355917a0c46c19853 (patch)
treebb7819b367680372d8d4071384df307d2b96ff01
parent084b0d96dd50d6d265792d9e200d9f2d6e8fa899 (diff)
downloadperlweeklychallenge-club-658e60b76deb452bf572385355917a0c46c19853.tar.gz
perlweeklychallenge-club-658e60b76deb452bf572385355917a0c46c19853.tar.bz2
perlweeklychallenge-club-658e60b76deb452bf572385355917a0c46c19853.zip
oops! found a serious error in my PrimeFactors() function last week.. fixed
-rw-r--r--challenge-168/duncan-c-white/perl/PrimeFactors.pm4
1 files changed, 1 insertions, 3 deletions
diff --git a/challenge-168/duncan-c-white/perl/PrimeFactors.pm b/challenge-168/duncan-c-white/perl/PrimeFactors.pm
index 5ec2210764..95c5043d15 100644
--- a/challenge-168/duncan-c-white/perl/PrimeFactors.pm
+++ b/challenge-168/duncan-c-white/perl/PrimeFactors.pm
@@ -40,7 +40,7 @@ fun prime_factors( $n )
{
die "prime_factors: n ($n) must be >1\n" if $n<=1;
my @result;
- my $lim = int(sqrt($n));
+ my $lim = $n;
my $orign = $n;
foreach my $f (2..$lim)
{
@@ -50,8 +50,6 @@ fun prime_factors( $n )
{
say "pf($orign): n=$n, adding $f to result" if $debug;
push @result, $f;
- my $other = $orign / $f;
- push @result, $other if isprime($other) && $other != $f;
$n /= $f;
say "pf($orign): n /= $f (so n=$n now)" if $debug;
}