Jump to content

Factorions: Difference between revisions

→‎{{header|Perl 6}}: Add a Perl 6 example
m (→‎{{header|Go}}: added zkl header)
(→‎{{header|Perl 6}}: Add a Perl 6 example)
Line 150:
1 2
</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2019.07.1}}
 
<lang perl6>constant @f = 1, |[\*] 1..*;
 
constant $limit = 1500000;
 
for 9 .. 12 -> $b {
 
say "\n\nFactorions in base $b:";
 
for ^$b { if $_ == @f[$_] { print "{$_} " } };
 
hyper for 1 .. $limit div $b -> $i {
my $sum;
my $prod = $i * $b;
 
for $i.polymod($b xx *) {
$sum += @f[$_];
$sum = 0 and last if $sum > $prod
}
 
next if $sum == 0;
 
print "{$sum + @f[$_]} " and last if $sum + @f[$_] == $prod + $_ for ^$b;
}
}</lang>
{{out}}
<pre>Factorions in base 9:
1 2 41282
 
Factorions in base 10:
1 2 145 40585
 
Factorions in base 11:
1 2 26 48 40472
 
Factorions in base 12:
1 2</pre>
 
=={{header|zkl}}==
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.