use Modern::Perl;
use Algorithm::Permute;
use List::AllUtils qw/uniq/;
find_perms(1151);
sub find_perms {
my ($value) = @_;
my @others;
my @digits = split(//, $value);
my $perm = Algorithm::Permute->new( \@digits );
while (my @next = $perm->next()) {
my $number = join('', @next);
push @others, $number;
}
@others = sort uniq @others;
# this one works correctly
# @others = sort ( uniq( @others ));
say "FOUND @others";
}
Output:
FOUND 1115 1115 1115 1115 1115 1115 1151 1151 1151 1151 1151 1151 1511 1511 1511 1511 1511 1511 5111 5111 5111 5111 5111 5111
你好,
在发现Algorithm::Permute正在产生重复项后,很可能是由于“1151”中的 '1' 数量我决定使用uniq
. 但是,sort uniq
不带括号使用不会产生预期的结果。但sort(uniq(@x))
确实如此。是什么赋予了?