I have a string array with 16 elements (A01,A02,A03,...,A14,A15,A16) and i would like to create a new string array which wil contais all of the combinations with 8 elements of this array. I need a code on how to complete this task.

# Combinations

0

Refer to All possible combinations of a string article.

0

A01A02A03A04A05A06A07A08

A01A02A03A04A05A06A07A09

A01A02A03A04A05A06A07A10

A01A02A03A04A05A06A07A11

. . . . . . . . . . . . .

. . . . . . . . . . . . .

A09A10A11A12A13A14A15A16

I hope you understand what i mean.

0

Say I identify A01 as X A02 as Y .... and then apply the above all combination to XY... and then resubstitute them when needed.

0

A01A02A03A04A05A06A07A08

A01A02A03A04A05A06A07A09

. . . . . . . . . . . .. . . . . . . . . . .

. . . . . . . . . . . . .. . . . . . . . . .

A09A10A11A12A13A14A15A16

And the program create combinations like this :

A01A02A03A04A05A06A07A08

A02A01A03A04A08A06A07A09

. . . . . . . . . . . .. . . . . . . . . . .

. . . . . . . . . . . . .. . . . . . . . . .

A16A10A11A12A13A14A15A09

If i have 8 of 16 combinations the new array must have 12870 combinatiosn not more.

I hope you understand what i mean now.

0

In that thread I have commented the complete source code and so that should help you more.

http://www.go4expert.com/showthread.php?p=3161

0

I will try to explain better what i would like to do. I will explain problem with smaller number of elements because 16 is too large to write all combinations.

Let say I have array with 6 elements {A,B,C,D,E,F}. Now i need to find combinations 4 of 6.

There are 15 combinations of 4 letters from this set ( n!/(r!(n-r)!)=6!/(2!(6-2)!)=15 ) and they are :

A B C D

A B C E

A B C F

A B D E

A B D F

A B E F

A C D E

A C D F

A C E F

A D E F

B C D E

B C D F

B C E F

B D E F

C D E F

What should I change in you code to have this. Maybe I can not explain good becouse English is not my mother language.

0

change to the required word.

Code: C

char str[]="G4EF"; // sample small word e.g. ABCDEF

Code: C

unsigned long num = fact(key[0]); // Chnage to n!/(r!(n-r)!)=6!/(2!(6-2)!)=15-1 = 14 as we loop till <= num

Code: C

for(int i=1;i<=k[0];i++) // change k[0] to (n-r) i.r. 4 in this case

0

Here are the combinations created with new code :

ABCD ABCD BCDE BCDE CDEF CDFE DEFA DEFA

EFAB EFAB FABC FABC ABCD ABCD

I will try to explayin again my problem detailed.

I need to enter two variables (not larger then 20) N and R (N must be larger then R).

for example N=6, R=4.

I create an CString array strArray with N (6) elements

strArray[0] = "A01"

. . . . . . . . . .

. . . . . . . . . .

strArray[5] = "A06"

Now I need to create all combinations with R (4) elements of this array and store them in some new array.

0

Quote:

ABCD ABCD BCDE BCDE CDEF CDFE DEFA DEFA

EFAB EFAB FABC FABC ABCD ABCD