Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Syntactic Confectionery Delight
 
PerlMonks  

Re: All possible number combinations in perl

by Cristoforo (Chaplain)
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 romping around the Monastery: (6)
As of 2014-04-20 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls