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

Re: All possible number combinations in perl

by Cristoforo (Deacon)
on Jun 08, 2012 at 15:54 UTC ( #975198=note: print w/ replies, xml ) Need Help??


in reply to All possible number combinations in perl

What you are looking for is called a powerset, with 2^n subsets. A collection of all possible sets from n items. For 2^5 == 32 possible sets (including the empty set).


Comment on Re: All possible number combinations in perl
Re^2: All possible number combinations in perl
by brx (Pilgrim) on Jun 10, 2012 at 08:24 UTC
    perl -e 'for my $i (1 .. (2<<4)-1){(1&($i>>$_)) && print 1+$_," " for +0..4; print"\n"} ' 1 2 1 2 3 1 3 2 3 1 2 3 4 1 4 2 4 1 2 4 3 4 1 3 4 2 3 4 1 2 3 4 5 1 5 2 5 1 2 5 3 5 1 3 5 2 3 5 1 2 3 5 4 5 1 4 5 2 4 5 1 2 4 5 3 4 5 1 3 4 5 2 3 4 5 1 2 3 4 5

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2015-07-04 16:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls