#! perl -slw
use strict;
use Data::Dump qw[ pp ];
use Algorithm::Combinatorics qw[ combinations ];
our $N //= 4;
our $K //= 2;
our $M //= 3;
my @AoA = map{
[ map int( rand 2 ), 1 .. $M ]
} 1 .. $N;
pp 'Input:', \@AoA;
my @newAoA;
my $i = combinations( \@AoA, $K );
while( my $comb = $i->next ) {
my @sums;
for my $a ( @{ $comb } ) {
$sums[ $_ ] += $a->[ $_ ] for 0 .. $#{ $a };
}
push @newAoA, \@sums;
}
pp 'Output:', \@newAoA;
__END__
c:\test>940693
("Input:", [[0, 1, 1], [0, 1, 1], [1, 0, 1], [0, 1, 0]])
(
"Output:",
[[0, 2, 2], [1, 1, 2], [0, 2, 1], [1, 1, 2], [0, 2, 1], [1, 1, 1]],
)
c:\test>940693 -N=5 -M=2 -K=3
("Input:", [[0, 1], [1, 0], [1, 1], [0, 1], [0, 0]])
(
"Output:",
[
[2, 2],
[1, 2],
[1, 1],
[1, 3],
[1, 2],
[0, 2],
[2, 2],
[2, 1],
[1, 1],
[1, 2],
],
)
c:\test>940693 -N=5 -M=4 -K=3
(
"Input:",
[
[1, 1, 1, 1],
[0, 1, 1, 0],
[1, 1, 0, 1],
[1, 1, 1, 1],
[0, 1, 1, 1],
],
)
(
"Output:",
[
[2, 3, 2, 2],
[2, 3, 3, 2],
[1, 3, 3, 2],
[3, 3, 2, 3],
[2, 3, 2, 3],
[2, 3, 3, 3],
[2, 3, 2, 2],
[1, 3, 2, 2],
[1, 3, 3, 2],
[2, 3, 2, 3],
],
)
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
|