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";
    }