Own digits power sum
(3..8).map: -> $p {
my %pow = (^10).map: { $_ => $_ ** $p };
my $start = 10 ** ($p - 1);
my $end = 10 ** $p;
my @temp;
for ^9 -> $i {
([X] ($i..9) xx $p).race.map: {
next unless [<=] $_;
my $sum = %pow{$_}.sum;
next if $sum < $start;
next if $sum > $end;
@temp.push: $sum if $sum.comb.Bag eqv $_».Str.Bag
}
}
.say for unique sort @temp;
}Output:
153
370
371
407
1634
8208
9474
54748
92727
93084
548834
1741725
4210818
9800817
9926315
24678050
24678051
88593477Combinations with repetitions
Using code from Combinations with repetitions task, a version that runs relatively quickly, and scales well.
Output:
Last updated
Was this helpful?