Vampire number: Difference between revisions

→‎{{header|Perl 6}}: more efficient code, add concurrency
m (→‎{{header|Perl}}: add libheader)
(→‎{{header|Perl 6}}: more efficient code, add concurrency)
Line 2,422:
my $digits = $num.comb.sort;
my @fangs;
for vfactors(10**$num.sqrt.log(10).floor .. $num.sqrt.ceiling).map: -> $this {
next if $num % $this;
my $that = $num div $this;
@fangs.push("next if $this x%% 10 && $that") if%% 10;
@fangs.push("$this x $that") if !($this %% 10 &&~ $that %% 10).comb.sort andeq $digits;
($this ~ $that).comb.sort eq $digits;
}
return @fangs;
}
 
constant @vampires = gather forflat (1 .. *).map: -> $ns, $e {
next if (10**$ns .log(. 10**$e).floorhyper.map: %%-> $n 2;{
next unless my @fangs = is_vampire($n);
take "$n: { @fangs.join(', ') }" if @fangs.elems;
}
}
 
Line 2,443 ⟶ 2,444:
say "\nIndividual tests:\n";
 
.say for (16758243290880, 24959017348650, 14593825548650).hyper(:1batch).map: {
print "$_: ";
my @fangs = is_vampire($_);
if"$_: " ~ (@fangs.elemsjoin(', {') || 'is not a vampire number.')
say @fangs.join(', ');
} else {
say 'is not a vampire number.';
}
}
 
sub vfactors (Int $n) {
map { $_ if $n %% $_ }, 10**$n.sqrt.log(10).floor .. $n.sqrt.ceiling;
}</lang>
 
<pre>First 25 Vampire Numbers:
<pre>
First 25 Vampire Numbers:
 
1260: 21 x 60
Line 2,490 ⟶ 2,481:
16758243290880: 1982736 x 8452080, 2123856 x 7890480, 2751840 x 6089832, 2817360 x 5948208
24959017348650: 2947050 x 8469153, 2949705 x 8461530, 4125870 x 6049395, 4129587 x 6043950, 4230765 x 5899410
14593825548650: is not a vampire number.</pre>
</pre>
 
=={{header|Phix}}==
10,333

edits