RosettaCodeData/Task/Permutations/Perl-6/permutations-3.pl6

14 lines
304 B
Raku
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
sub permute(+@items) {
2013-10-27 22:24:23 +00:00
my @seq := 1..+@items;
gather for (^[*] @seq) -> $n is copy {
my @order;
for @seq {
unshift @order, $n mod $_;
$n div= $_;
}
my @i-copy = @items;
2016-12-05 22:15:40 +01:00
take map { |@i-copy.splice($_, 1) }, @order;
2013-10-27 22:24:23 +00:00
}
}
.say for permute( 'a'..'c' )