As I mentioned in an earlier post, this construct isn't implemented yet in Pugs. Also as I said before, I may be using it incorrectly, but I think this could be implemented using gather/take as follows:
sub combinations returns Array (@list is rw) { return () unless @list.elems; gather { for 1 .. 2**@list.elems-1-> $num { take [ @list[ (0 .. sqrt($num)).grep:{ $num +& (2**$_) } ] ] +; } } } my @list = (1..4); combinations(@list).perl.say;
In reply to Re: P6: Combinations Solution
by revdiablo
in thread P6: Combinations Solution
by eric256
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |