Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Recursively-generated Iterators

by Roy Johnson (Monsignor)
on May 18, 2005 at 20:04 UTC ( [id://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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-28 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found