# Need a help in two dimentaional permutation

• 08-05-2011, 07:17 AM
venk123
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
• 08-05-2011, 07:22 AM
Junky
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.
• 08-05-2011, 07:57 AM
Hibernate
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.
• 08-05-2011, 08:07 AM
Hibernate
Deciphering this I suppose you intended[!] to write:

Code:

```⎛aaa  aab  aba  abb  baa  bab  bba  bbb⎞ ⎝aaa  aab  abb  baa  bbb  aba  bab  bba⎠```
(And thank "God" that is a permutation!)
• 08-05-2011, 08:10 AM
pbrockway2
@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.
• 08-05-2011, 08:15 AM
Hibernate
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:
Code:

```final int[] π = {0, 1, 3, 4, 7, 2, 5, 6}; //as a static (constant) variable in the class output = encode(π[decode(input)]);```
• 08-05-2011, 10:39 AM
venk123
Yes Pbrockway2 ... I need to write program for 2^3 sequence of double digit number ....please help
• 08-06-2011, 01:28 AM
pbrockway2
Quote:

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?