Need help finding all possible combinations, method almost complete
I can't seem to get this code to work. What I am doing is populating an
array with all possible combinations of 2 digits (each of these digits
representing a shape and color, respectively). Then, I am trying to use
this array to populate a 2d array in which i create all possible
combinations of the elements housed in the previous array. For some
reason, my 2d array is filled with all '21' instead of any sort of
combination.
I can post the rest of the code in the class if needed, but it's rather
long. The final loop in this method is just used to print them for testing
and will be deleted afterwards.
public void combinations()
{
combinations = new int[numShapes*numColors];
int index = 0;
for(int l = 1; l <= numShapes; l++)
for(int h = 1; h <= numColors; h++)
if(index + 1 != combinations.length + 1)
combinations[index++] = (l*10) + h;
else
break;
int[][] combs = new
int[(int)Math.pow((numShapes*numColors),numPositions)][numPositions];
//Fills the array with all '21' , fix this
int ind = 0;
for(int f = 0; f < 16; f++)
for(int i = 0; i < numShapes; i++)
for(int j = 0; j < numColors; j++)
if(ind != combs.length+1){
combs[ind] = new int[]{combinations[numShapes],
combinations[numShapes], combinations[numColors]};
ind++;
}
else
break;
for(int p = 0; p < 2; p++){
for(int g = 0; g < 3; g++){
System.out.print(testFormat(combs[p][g]/10, combs[p][g]%10) +
" ");
}
System.out.println();
}
}
No comments:
Post a Comment