# Challenging permutation - combination of strings

N Vinod

Greenhorn

Posts: 2

posted 14 years ago

Hey guys, here is some real brain twisting tough one...tough for me atleast....

If i have a set of values, say,

ABCDE

GHIJKL

MNOPQR

each line stored as an array of Strings, where the number of rows and colunmns can be dynamic and much larger.

I need to get the following output, for a permutation of data of "3 element combinations"

1)

ABC

GHI

MNO

2)

BCD

HIJ

NOP

3)

CDE

IJK

OPQ

4)

DEF

JKL

PQR

5)

ABD

GHJ

MNP

6)

ACD

GIJ

MOP

and so on..............

I was able to obtain the first four combinations, as it is pretty straight forward, using "for loops" and incrementing the values in substring() method.

What do u think i can do to get the remaining outputs, like output numbe five and greater ??Please note that

CBA

IHG

ONM

is not needed as it is similar to the first output.

Instead of "3 element combinations"... i should be able to give "4 element combination" and get the corresponding output for it.

I have been working on this for a long time, on and off for more than a month, do let me know of your valuable tips.

thanks

If i have a set of values, say,

ABCDE

GHIJKL

MNOPQR

each line stored as an array of Strings, where the number of rows and colunmns can be dynamic and much larger.

I need to get the following output, for a permutation of data of "3 element combinations"

1)

ABC

GHI

MNO

2)

BCD

HIJ

NOP

3)

CDE

IJK

OPQ

4)

DEF

JKL

PQR

5)

ABD

GHJ

MNP

6)

ACD

GIJ

MOP

and so on..............

I was able to obtain the first four combinations, as it is pretty straight forward, using "for loops" and incrementing the values in substring() method.

What do u think i can do to get the remaining outputs, like output numbe five and greater ??Please note that

CBA

IHG

ONM

is not needed as it is similar to the first output.

Instead of "3 element combinations"... i should be able to give "4 element combination" and get the corresponding output for it.

I have been working on this for a long time, on and off for more than a month, do let me know of your valuable tips.

thanks

Dirk Schreckmann

Sheriff

Posts: 7023

posted 14 years ago

Vinod,

We try to keep a given conversation contained to a single thread. It makes it much easier to follow, participate in, and learn from the conversation. I've closed your original posting and included a link from it to here.

Thanks

[ May 14, 2002: Message edited by: Dirk Schreckmann ]

We try to keep a given conversation contained to a single thread. It makes it much easier to follow, participate in, and learn from the conversation. I've closed your original posting and included a link from it to here.

Thanks

[ May 14, 2002: Message edited by: Dirk Schreckmann ]

It is sorta covered in the JavaRanch Style Guide. |