Proper divisors: Difference between revisions

→‎{{header|Perl 6}}: Concurrency doesn't really help, simplified, use more efficient ops
(Matlab section)
(→‎{{header|Perl 6}}: Concurrency doesn't really help, simplified, use more efficient ops)
Line 2,837:
 
=={{header|Perl 6}}==
{{Works with|rakudo|2015-2018.10-31}}
<lang perl6>sub propdiv (\x) {
my @l =( 1 if x > 1), gather for 2 .. x.sqrt.floor -> \d {;
(2 .. x.sqrt.floor).map: my-> \yd = x div d;{
ifunless yx *% d ={ @l.push: d; my \y = x { takediv d; take@l.push: y unlessif y =!= d }
}
}@l
gather @l.deepmap(*.take);
}
 
sayput "$_ ", [{propdiv($_)}]" for 1..10;
 
my $max = 0;
my @candidates;
forloop (my int $c = 1..; $c <= 20000; $c += 1) {
my @pd = candidates[+propdiv($_c);].push: $c
my $pd = @pd.elems;
if $pd > $max {
@candidates = ();
$max = $pd;
}
push @candidates, $_ if $pd == $max;
}
 
say "max = $max{@candidates - 1}, candidates = {@candidates[].tail}";</lang>
{{out}}
<pre>1 Nil []
2 1 [1]
3 1 [1]
4 [1 2]
5 1 [1]
6 [1 2 3]
7 1 [1]
8 [1 2 4]
9 [1 3]
10 [1 2 5]
max = 79, candidates = 15120 18480</pre>
 
10,333

edits