# Thread: Need a help in two dimentaional permutation

1. Member
Join Date
Feb 2011
Posts
9
Rep Power
0

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

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

5. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14
@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. 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]

7. Member
Join Date
Feb 2011
Posts
9
Rep Power
0
Yes Pbrockway2 ... I need to write program for 2^3 sequence of double digit number ....please help

8. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14
Originally Posted by venk123
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?

#### Posting Permissions

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