Skip to content

Instantly share code, notes, and snippets.

@colomon
Created February 18, 2013 02: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 colomon/4974879 to your computer and use it in GitHub Desktop.
Save colomon/4974879 to your computer and use it in GitHub Desktop.
sub combinations(@items, $count) is export {
my $size = +@items;
gather for ^(2 ** $size) -> $i {
my $gray = $i +^ ($i +> 1);
my @a = @items.grep({ my $result = $gray +& 1; $gray +>= 1; $result });
next if @a != $count;
take [@a];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment