4
I have the following matrix:
a d k m s j e r t c f p
I put such a matrix in an array as follows:
char[,] matriz = new char[3,4];
matriz[0,0] = 'a';
matriz[0,1] = 'd';
matriz[0,2] = 'k';
matriz[0,3] = 'm';
matriz[1,0] = 's';
// E assim sucessivamente.
I would like to generate all possible sets based on such an array, taking into account the number of columns to determine the size of the set.
In the example cited above, it would be possible to create (3 4) 81 different sets.
Ex.:
[1] "adkm" [4] "adem" [8] "adfm" [11] "ajkm"
[2] "adkr" [5] "ader" [9] "adfr" [12] "ajkr"
[3] "adkp" [7] "adep" [10] "adfp" [13] "ajkp"
What would be the best way to scan this array and create column-based sets?
int qtdColunas = 4;
char[] conjunto1 = new char[qtdColunas];
conjunto1[0] = 'a';
conjunto1[1] = 'd';
conjunto1[2] = 'k';
conjunto1[3] = 'm';
char[] conjunto2 = new char[qtdColunas];
conjunto1[0] = 'a';
conjunto1[1] = 'd';
conjunto1[2] = 'k';
conjunto1[3] = 'r';
char[] conjunto3 = new char[qtdColunas];
conjunto1[0] = 'a';
conjunto1[1] = 'd';
conjunto1[2] = 'k';
conjunto1[3] = 'p';
I tried to find on the web something already ready, but I don’t know exactly name what I’m doing.
I would like a solution clean, fast and with little memory consumption.
The matrix given in the question is just an example, because in my code I can build larger matrices. And of course I don’t fill it out line by line as I exemplified.
I believe it is only a question of logic, but good practice makes a lot of difference at this time. By being starting out, I wouldn’t want to make more mistakes than acceptable.
Man, if I could give you + 2, I would! Thank you very much, it worked perfectly. And using primitive types got the way I wanted it.
– Jedaias Rodrigues