tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View 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>!

View 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 ...^ !*;