You have a lot of problems in that program. There's a mismatch in your data types.
If you want to use frequency
, you only specify the unique elements once but specify how many times they appear. The array reference you give to frequency has to be the same length as your data array:
use Math::Combinatorics;
my @array = (1,0); # an array, not an array reference
$c = Math::Combinatorics->new(
count => 5,
data => \@array, # now you take a reference
frequency => [3,2]
);
while (@permu = $c->next_string ){
print "@permu\n";
}
Now you should get the output you wanted, which are the distinct combinations where you can't tell the difference between the multiple 1's and multiple 0's:
0 1 1 1 0
0 1 1 0 1
0 1 0 1 1
0 0 1 1 1
1 0 1 1 0
1 0 1 0 1
1 0 0 1 1
1 1 0 1 0
1 1 0 0 1
1 1 1 0 0
If you don't use frequency
, you just have to specify all the elements in the data array. However, you're probably avoiding that because it treats every element as distinct so it doesn't collapse what look like the same combination.