LoginSignup
2
2

More than 5 years have passed since last update.

順列列挙

Posted at
next_permutation.pl
sub next_permutation {    my $ary = shift;    return unless ref($ary) eq 'ARRAY';    my $last = $#$ary or return;    my $i = $last;    while ($ary->[$i-1] > $ary->[$i]) {        return unless $i-- > 1;    }    my $j = $last;    while ($ary->[$i-1] > $ary->[$j]) {        $j--;    }    @$ary[$i-1, $j] = @$ary[$j, $i-1];    @$ary[$i..$last] = reverse @$ary[$i..$last];    return 1;}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2