in reply to P6: Combinations Solution
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: P6: Combinations Solution
by eric256 (Parson) on May 21, 2005 at 20:27 UTC | |
by revdiablo (Prior) on May 22, 2005 at 23:29 UTC |