in reply to Re^2: adding combinations of arrays (of arrays)
in thread adding combinations of arrays (of arrays)

That is much clearer. You want something like this?

#! 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".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^4: adding combinations of arrays (of arrays)
by Anonymous Monk on Nov 30, 2011 at 01:12 UTC
    Looks good, never seen some of that syntax you used to set the command line parameters. Thanks!
      never seen some of that syntax you used to set the command line parameters

      Notice the -s on the shebang line and then look it up in perlrun.

      It is very simple, and I like simple.


      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".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?