Results 1 to 8 of 8
  1. #1
    venk123 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default Need a help in two dimentaional permutation

    Hi!

    I need help writing java code for the following permutations....


    Input : a=(0,32)
    b=(32,64)

    Lenghth: 3 (Means 2 power 3 i need 8 combinations)

    output:

    0 32
    0 32
    0 32

    0 32
    0 32
    32 64

    0 32
    32 64
    32 64

    32 64
    0 32
    0 32

    32 64
    32 64
    32 64

    0 32
    32 64
    0 32

    32 64
    0 32
    32 64

    32 64
    32 64
    0 32

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    It is difficult to offer advice when I don't have a friggin clue what the code is supposed to do.

    However, what you need to do is grab some paper and write down clear and precise steps of how to generate that desired output. Once you have done that, writing the code should be simple.

  3. #3
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    Yeaahh, that does not look like a permutation, I think you need to clarify the output, what is it, is it two row nationation, one row notation, [god forbid in this case] cycle notation? What are we dealing with?

    Also clarify a and b while you are on that.

    Edit:
    Ohh, a and b are obviously the elements, sorry.
    Last edited by Hibernate; 08-05-2011 at 08:00 AM.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  4. #4
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    Deciphering this I suppose you intended[!] to write:

    Java Code:
    ⎛aaa  aab  aba  abb  baa  bab  bba  bbb⎞
    ⎝aaa  aab  abb  baa  bbb  aba  bab  bba⎠
    (And thank "God" that is a permutation!)
    Last edited by Hibernate; 08-05-2011 at 08:17 AM.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    @OP: do you mean all sequences of length 3 made up of a and b? Ie aaa, aab, abb, baa, bbb, aba, bab, bba?

    If so - or in any case - Junky's advice is good. Think about how you would list all 8=2^3 sequences. Your list seems to be ordered somewhat randomly (to my eye). I might have chosen something with a pattern so I was sure not to leave any out: aaa, aab, aba, abb, baa, bab, bba, bbb.

  6. #6
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    I would suggest decoding into integers (aaa = 0, aab = 1, aba = 2, …) and just use a look-up-table and return the return value encoded:
    Java Code:
    final int[] π = {0, 1, 3, 4, 7, 2, 5, 6}; //as a static (constant) variable in the class
    output = encode(π[decode(input)]);
    Last edited by Hibernate; 08-05-2011 at 08:31 AM. Reason: whoops, typo two 4:s [whoops, typo in typo note]
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  7. #7
    venk123 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    Yes Pbrockway2 ... I need to write program for 2^3 sequence of double digit number ....please help

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Quote Originally Posted by venk123 View Post
    Yes Pbrockway2 ... I need to write program for 2^3 sequence of double digit number ....please help
    Did you try follow Junky's advice and try and make clear the steps you (rather than a computer) would follow? After all you must have done something to arrive at the sequence in your original post. If so what results did you get?

    Did you think about the particular pattern to the sequence I suggested as an alternative (and which Hibernate used)? Is there some way that loops (or other programming constructs you have seen) could be used to generate that pattern? Have you seen patterns like this elsewhere?

Similar Threads

  1. Permutation
    By Claymz in forum New To Java
    Replies: 4
    Last Post: 06-01-2011, 02:27 PM
  2. Replies: 3
    Last Post: 08-24-2009, 07:39 PM

Posting Permissions

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