Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Recursively-generated Iterators

by Roy Johnson (Monsignor)
on May 18, 2005 at 20:04 UTC ( #458418=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # Given a list of M items and a number N,
    # generate all size-N subsets of M
    ...
        return ( (map {[$first, @$_]} @include_combos)
             , @exclude_combos );
    }
    
  2. or download this
    sub iter_choose_n {
        my $n = pop;
    ...
        return sub {$once++ ? () : []} if $n == 0  or $n > @_;
        my ($first, @rest) = @_;
        return sub {$once++ ? () : [$first, @rest]} if $n == @_;
    
  3. or download this
        # otherwise..
        my $include_iter = iter_choose_n(@rest, $n-1);
    ...
                return $exclude_iter->();
            }
        }
    
  4. or download this
        # otherwise..
        my $include_iter = iter_choose_n(@rest, $n-1);
    ...
            }
        }
    }
    
  5. or download this
        # otherwise..
        my $include_iter = iter_choose_n(@rest, $n-1);
    ...
            }
        }
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://458418]
Approved by blokhead
Front-paged by blokhead
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (18)
As of 2015-07-29 12:53 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 (263 votes), past polls