Results 1 to 5 of 5
- 01-18-2009, 01:09 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 3
- Rep Power
- 0
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, 01:19 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Just loop through all the elements and validate that element value is valid with your requirement.
- 01-18-2009, 01:37 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 3
- Rep Power
- 0
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, 02:18 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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, 08:42 AM #5
Member
- Join Date
- Jan 2009
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Help with dox matrix printer
By Albert in forum Advanced JavaReplies: 7Last Post: 09-06-2011, 08:50 AM -
while Loop (Repetition) structure.
By gapeach97 in forum New To JavaReplies: 9Last Post: 12-03-2008, 11:52 PM -
repetition of 'arguments'(?)
By Igor in forum New To JavaReplies: 3Last Post: 12-13-2007, 10:08 AM -
Help with matrix
By susan in forum New To JavaReplies: 1Last Post: 08-07-2007, 04:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks