Your skill will accomplishwhat the force of many cannot PerlMonks

### Comment on

 ( #3333=superdoc: print w/ replies, xml ) Need Help??

Sure. No need to do any recursion here. Just count in binary. Here is a version that creates a closure (an anonymous subroutine that holds the needed data inside of itself -- sort of like a tiny "object") that returns the next combination each time it is called:

```sub combinations {
my @list= @_;
my @pick= (0) x @list;
return sub {
my \$i= 0;
while( 1 < ++\$pick[\$i]  ) {
\$pick[\$i]= 0;
return   if  \$#pick < ++\$i;
}
return @list[ grep \$pick[\$_], 0..\$#pick ];
};
}
my \$next= combinations( 50..59 );
my @comb;
while(  @comb= \$next->()  ) {
# do work with @comb here
}
# Note that the empty set is a valid combination but is
# the last combination returned which also indicates "no
# more combinations left.  So the above loop doesn't bother
# processing the empty list.  If you want to process the
# empty set, then use:
my @comb;
do {
# do work with @comb here
} while(  @comb= \$next->() );

Update: My code finds combinations but the original code finds permutations even though the author asked for combinations. (See (tye)Re: Permutations if you don't know the difference between the two.)

Of course, my favorite way of finding permutations is Permuting with duplicates and no memory.

- tye (but my friends call me "Tye")

In reply to (tye)Re: Finding all Combinations by tye
in thread Finding all Combinations by narse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (15)
As of 2016-05-06 14:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What font do you use for programming?

Results (118 votes). Check out past polls.