Primes - allocate descendants to their ancestors: Difference between revisions

Content added Content deleted
(Added Perl example)
m (→‎{{header|Perl}}: added lib header)
Line 1,026:
=={{header|Perl}}==
{{trans|Perl 6}}
{{libheader|ntheory}}
<lang perl>use List::Util qw(sum uniq);
use ntheory qw(nth_prime);
Line 1,057 ⟶ 1,058:
 
allocate($_) for 1 .. $max;
 
$total = 0;
map { for my $k (keys %{$tree{$_}{descendants}}) { $total += $tree{$_}{descendants}{$k} } } 1..$max;
 
for (1 .. 15, 46, $max) {
Line 1,071 ⟶ 1,069:
printf "%5d Descendants: %s", $dn, "[$dl]\n";
}
 
print "Total descendants: $total\n";</lang>
map { for my $k (keys %{$tree{$_}{descendants}}) { $total += $tree{$_}{descendants}{$k} } } 1..$max;
print "Total\nTotal descendants: $total\n";</lang>
{{out}}
<pre> 1, 0 Ancestors: [], 0 Descendants: []