Skip to content

Commit 294bc61

Browse files
committed
[euler/prob003] simplify algorithm
composite numbers won't divide the reduced $n as their factors have already been seen and divided out
1 parent 1f2506c commit 294bc61

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

euler/prob003-gerdr-cheating.pl

Lines changed: 0 additions & 13 deletions
This file was deleted.

euler/prob003-gerdr.pl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use v6;
22

33
sub largest-prime-factor($n is copy) {
4-
my @primes;
54
for 2, 3, *+2 ... * {
6-
next if $_ %% any @primes.grep(->$p { $p * $p <= $_ or last });
7-
@primes.push($_);
85
while $n %% $_ {
9-
$n div= $_
6+
$n div= $_;
7+
return $_ if $_ > $n;
108
}
11-
return $_ if $_ > $n;
129
}
1310
}
1411

0 commit comments

Comments
 (0)