in reply to Re^3: Generating powerset with progressive ordering
in thread Generating powerset with progressive ordering
A powerset should always include the empty set. (The cardinality of the powerset of a set of cardinality n should be 2n.) Therefore, you can simplify powerset:
I imagine that this means that only two states are needed in iter_powerset.sub powerset { my ( $car, @cdr ) = @_; my @cdr_powerset = @cdr ? powerset( @cdr ) : []; return ( @cdr_powerset, map [ $car, @$_ ], @cdr_powerset ); }
the lowliest monk
In Section
Seekers of Perl Wisdom