Jump to content

Ordered partitions: Difference between revisions

→‎{{header|Perl 6}}: provisional fix
m (→‎{{header|Perl 6}}: mark as broken)
(→‎{{header|Perl 6}}: provisional fix)
Line 1,561:
 
=={{header|Perl 6}}==
{{works with|nieczaRakudo|2012-062018.04.1}}
{{broken|Perl 6}}
{{works with|niecza|2012-06}}
<lang perl6>sub partition(@mask is copy) {
my @op;
my $last = [+] @mask or return [[] xx @mask];
sortmy gather$last for= [+] @mask.kv ->or $k,$vreturn [] xx {1;
for @mask.kv -> $k, $v {
next unless $v;
temp @mask[$k] -= 1;
for partition @mask {-> .take.[$k].push($last)@p }{
@p[$k].push: $last;
@op.push: @p;
}
}
return @op;
}
 
.perl.say for reverse partition [2,0,2];</lang>
{{out}}
<pre>[[1, 2], [](Any), [3, 4]]
[[1, 3], [](Any), [2, 4]]
[[2, 3], [](Any), [1, 4]]
[[1, 4], [](Any), [2, 3]]
[[2, 4], [](Any), [1, 3]]
[[3, 4], [](Any), [1, 2]]</pre>
 
=={{header|Phix}}==
2,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.