Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Generating powerset with progressive ordering

by tlm (Prior)
on Apr 26, 2005 at 23:46 UTC ( [id://451800]=note: print w/replies, xml ) Need Help??


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

Replies are listed 'Best First'.
Re^5: Generating powerset with progressive ordering
by Roy Johnson (Monsignor) on Apr 27, 2005 at 02:38 UTC
    That does simplify it, but it throws off the progressive ordering, which worked out almost magically the way I had it written. For the problem L~R was looking to solve, it was not useful to consider the empty set, either. Probably I should rename the function "non-empty powerset". :-)

    ++ for technical merit.


    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://451800]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-19 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found