Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 chilling in the Monastery: (6)
As of 2014-12-28 03:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls