Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: Obtaining terms in an expansion

by ivancho (Hermit)
on Jan 06, 2006 at 22:19 UTC ( #521661=note: print w/replies, xml ) Need Help??


in reply to Re^4: Obtaining terms in an expansion
in thread Obtaining terms in an expansion

I guess that's as good as it gets from Math::Combinatorics - doable, but not very natural.

There are plenty of other iterators out there that give all the subsets, though - List::PowerSet, Data::PowerSet, Algorithm::ChooseSubsets - We just have to convert them to give a bit mask instead - ie:

use List::PowerSet qw/powerset_lazy/; my @set = (0) x $N; my @C = (1) x 2**$N; my $M = 0; my $ps_itr = powerset_lazy(0 .. $N-1); while (my $ref_set = $ps_itr->()) { $_ = 1 for local @set[@$ref_set]; $C[ $M ] *= $arr->[ $_ ][ $set[$_] ] for 0 .. $N-1; $M++; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2021-05-08 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (96 votes). Check out past polls.

    Notices?