http://www.perlmonks.org?node_id=451800


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:

sub powerset { my ( $car, @cdr ) = @_; my @cdr_powerset = @cdr ? powerset( @cdr ) : []; return ( @cdr_powerset, map [ $car, @$_ ], @cdr_powerset ); }
I imagine that this means that only two states are needed in iter_powerset.

the lowliest monk