Proper divisors: Difference between revisions

Content added Content deleted
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: Line 2,838:
=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{Works with|rakudo|2018.10}}
{{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) {
<lang perl6>sub propdiv (\x) {
my @l = 1 if x > 1;
my @l = 1 if x > 1;
Line 2,849: Line 2,852:


my @candidates;
my @candidates;
loop (my int $c = 1; $c <= 20000; $c += 1) {
loop (my int $c = 10; $c <= 20_000; $c += 10) {
#(10, *+10 ... 200_000).race.map: -> $c {
@candidates[+propdiv($c)].push: $c
my \mx = +propdiv($c);
next if mx < @candidates - 1;
@candidates[mx].push: $c
}
}