Jump to content

Proper divisors: Difference between revisions

→‎{{header|Perl 6}}: Optimize, add some verbiage about optimization and concurrency
m (Undo revision 272833 by Gerard Schildberger (talk) edited wrong page.)
(→‎{{header|Perl 6}}: Optimize, add some verbiage about optimization and concurrency)
Line 2,838:
=={{header|Perl 6}}==
{{Works with|rakudo|2018.10}}
Once your threshold is over 1000, the maximum proper divisors will always include 2 and 5 as divisors, so only bother to check multiples of 2 and 5.
 
There really isn't any point in using concurrency for a limit of 20_000. The setup and bookkeeping drowns out any benefit. Really doesn't start to pay off until the limit is 50_000 and higher. Try swapping in the commented out race map iterator line below for comparison.
<lang perl6>sub propdiv (\x) {
my @l = 1 if x > 1;
Line 2,849 ⟶ 2,852:
 
my @candidates;
loop (my int $c = 110; $c <= 2000020_000; $c += 110) {
#(10, *+10 ... 200_000).race.map: -> $c {
@candidates[+propdiv($c)].push: $c
my \mx = +propdiv($c);
next if mx < @candidates - 1;
@candidates[+propdiv($c)mx].push: $c
}
 
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.