Amicable pairs: Difference between revisions

Content deleted Content added
Trizen (talk | contribs)
→‎{{header|Sidef}}: simplification: use the sigma function
SqrtNegInf (talk | contribs)
m →‎{{header|Perl 6}}: faster: concurrency & improved 'sum' routine
Line 2,972:
 
=={{header|Perl 6}}==
{{Works with|rakudoRakudo|2015-10-312019.03.1}}
<lang perl6>sub propdivsum (\x) {
my @l = x > 1, gather for 2 ..if x.sqrt.floor -> \d {1;
(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 }
}
[+] gathersum @l.deepmap(*.take);
}
 
for (1..20000).race.map: -> $i {
my $j = propdivsum($i);
say "$i $j" if $j > $i and $i == propdivsum($j);