Skip to content

Instantly share code, notes, and snippets.

@TimToady
Created May 31, 2012 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimToady/2847343 to your computer and use it in GitHub Desktop.
Save TimToady/2847343 to your computer and use it in GitHub Desktop.
sub partition(@mask is copy) {
my $last = [+] @mask or return [[] xx @mask];
sort gather for @mask.kv -> $k,$v {
next unless $v;
temp @mask[$k] -= 1;
for partition @mask { .take.[$k].push($last) }
}
}
.perl.say for partition [2,0,2];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment