RosettaCodeData/Task/Ordered-Partitions/Perl-6/ordered-partitions.pl6

16 lines
334 B
Raku
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
sub partition(@mask is copy) {
2018-06-22 20:57:24 +00:00
my @op;
my $last = [+] @mask or return [] xx 1;
for @mask.kv -> $k, $v {
2013-04-10 23:57:08 -07:00
next unless $v;
temp @mask[$k] -= 1;
2018-06-22 20:57:24 +00:00
for partition @mask -> @p {
@p[$k].push: $last;
@op.push: @p;
}
2013-04-10 23:57:08 -07:00
}
2018-06-22 20:57:24 +00:00
return @op;
2013-04-10 23:57:08 -07:00
}
2018-06-22 20:57:24 +00:00
.say for reverse partition [2,0,2];