Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Iterating over combinations

by blokhead (Monsignor)
on Jul 01, 2004 at 20:11 UTC ( [id://371228]=CUFP: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    ## Filtering tye's "combinations" (power set) iterator:
    my $iter = combinations(@S);
    ...
        next unless @c == $K;
        ...
    }
    
  2. or download this
    ## Using tye's Algorithm::Loops:
    NestedLoops(
    ...
        ( sub { [$_+1 .. $#S] } ) x ($K - 1),
        sub { my @c = @S[@_]; ... }
    }
    
  3. or download this
    sub combinations {
        my ($num, $arr) = @_;
    ...
            return @$arr[@pick];
        };
    }
    
  4. or download this
    my $iter = combinations( 3 => ['a' .. 'f'] );
    
    while ( my @c = $iter->() ) {
        print "@c\n";
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://371228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-23 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found