Maybe this solution - however it does not rely on file2 to calculate the combinations. That is done instead using
Algorithm::Combinatorics.
#!/usr/bin/perl
use strict;
use warnings;
use Algorithm::Combinatorics 'subsets';
my @headers = split ' ', scalar <DATA>;
my @data = map [split], <DATA>;
my @subsets;
for my $k (3, 4) {
push @subsets, subsets([0 .. $#headers], $k);
}
for my $indices (@subsets) {
my $count = 0;
for my $aref (@data) {
++$count unless grep $_ eq '0', @$aref[ @$indices ];
}
print "@headers[ @$indices ]\t$count\n";
}
__DATA__
A B C D E
0 0 0 + 0
+ 0 + + +
0 + + + +
0 0 + + 0
+ + + + +
0 + + + +
+ 0 + + 0
The output is
A B C 1
A B D 1
A B E 1
A C D 3
A C E 2
A D E 2
B C D 3
B C E 3
B D E 3
C D E 4
A B C D 1
A B C E 1
A B D E 1
A C D E 2
B C D E 3
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.