tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
8
Task/Permutations/Perl-6/permutations-1.pl6
Normal file
8
Task/Permutations/Perl-6/permutations-1.pl6
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
sub postfix:<!>(@a) {
|
||||
@a == 1 ?? [@a] !!
|
||||
gather for @a -> $a {
|
||||
take [ $a, @$_ ] for @a.grep(none $a)!
|
||||
}
|
||||
}
|
||||
|
||||
.say for <a b c>!
|
||||
16
Task/Permutations/Perl-6/permutations-2.pl6
Normal file
16
Task/Permutations/Perl-6/permutations-2.pl6
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
sub next_perm ( @a is copy ) {
|
||||
my $j = @a.end - 1;
|
||||
return Nil if --$j < 0 while @a[$j] after @a[$j+1];
|
||||
|
||||
my $aj = @a[$j];
|
||||
my $k = @a.end;
|
||||
$k-- while $aj after @a[$k];
|
||||
@a[ $j, $k ] .= reverse;
|
||||
|
||||
my $r = @a.end;
|
||||
my $s = $j + 1;
|
||||
@a[ $r--, $s++ ] .= reverse while $r > $s;
|
||||
return $(@a);
|
||||
}
|
||||
|
||||
.say for [<a b c>], &next_perm ...^ !*;
|
||||
Loading…
Add table
Add a link
Reference in a new issue