Matrix variations with repetition

• 01-18-2009, 02:09 PM
jnovice
Matrix variations with repetition
Hello,

i am looking for algorithm how to genereate all variations with repetitions from two dimensional matrix. There are always trhree columns and row numbers is optional (row count > 1). All three fields in a row need not be filled. Lets assume there is a matrix like this:

1 2 3
A x x -
B - x x
C x x x

final variations will be:

A1C1
A1C2
A1C3
A1B2C1
A1B2C2
A1B2C3
A1B3C1
A1B3C2
A1B3C3
A2C1
A2C2
A2C3
A2B2C1
A2B2C2
A2B2C3
B3C1
B3C2
B3C3

Some idea? Thank you.
• 01-18-2009, 02:19 PM
Eranga
Just loop through all the elements and validate that element value is valid with your requirement.
• 01-18-2009, 02:37 PM
jnovice
I am afraid I do know how to generate all variations with repetition. There imho should be recursion.

This is not a soltion, this code does not generate variations.

public static void main(String[] args) {
int[][] test = new int[2][2];
for(int i=0; i< test.length; i++){
for(int p=0; p< test[i].length; p++){
System.out.println( "["+ String.valueOf(i) + "," + String.valueOf(p) + "]" );
}
}
}
• 01-19-2009, 03:18 AM
Eranga
I'm not clear exactly what you want to do. If I'm correct, what you want to do is find all combination in the array(matrix as you said). Since you don't want to worry about the repeating something, what's the problem with this?
• 01-19-2009, 09:42 AM
jnovice
Hi,

I need variations with repetition, no combination and no permutation.

There si an example i my first post and it describes what I need.

I think there is need to be recursive function which will do these variations, but I now can not imagine this algorithm.