Results 1 to 5 of 5
  1. #1
    jnovice is offline Member
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Default 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.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Just loop through all the elements and validate that element value is valid with your requirement.

  3. #3
    jnovice is offline Member
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Default

    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) + "]" );
    }
    }
    }

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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?

  5. #5
    jnovice is offline Member
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Default

    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.

Similar Threads

  1. Help with dox matrix printer
    By Albert in forum Advanced Java
    Replies: 7
    Last Post: 09-06-2011, 08:50 AM
  2. while Loop (Repetition) structure.
    By gapeach97 in forum New To Java
    Replies: 9
    Last Post: 12-03-2008, 11:52 PM
  3. repetition of 'arguments'(?)
    By Igor in forum New To Java
    Replies: 3
    Last Post: 12-13-2007, 10:08 AM
  4. Help with matrix
    By susan in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 04:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •