Combinatorics Library
in
Contributed Library Questions
•
1 year ago
Hello everyone,
I have just started to use the new Combinatorics library and have a problem of storing all resulting combinations as a two-dimensional array. The code is:
import de.bezier.math.combinatorics.*;
int posTaken [] = {4,8,1,2,10,3,11};
// ==== get all possible 4-element combinations of positions taken by player
Combination combinations = new Combination(posTaken.length, 4 );
while ( combinations.hasMore () )
{
int[] c = combinations.next();
for ( int i = 0; i < c.length; i++ )
{
print(posTaken[ c[i] ]+",");
}
println();
// prints 4,8,1,2,
4,8,1,10,
4,8,1,3,
4,8,1,11,
...
...etc
}
However, I would like to store all possible results as a two-dimensional array, i.e. { {4,8,1,2},{4,8,1,10},{4,8,1,3},{4,8,1,11},{...} }. Does anyone know what is the best way to do this?
1