MS Excel, 2002.
I'm trying to get a macro to write all possible partitions of a set of elements, where the elements are given as a string of letters.
I've searched and found a small number of posts that refer to _breaking_ a word, line, sentence, etc. into two parts by simply chopping it somewhere in the middle. But I need different _permutations_ of elements at the same time.
The input will be strings of letters with no repeats, and the letters should be partitioned into two (non-empty) sets. Find all such partitions.
Example: Given a cell containg the letters ABCD, the output should be (in two columns)
A | BCD
B | ACD
C | ABD
D | ABC
AB | CD
AC | BD
AD | BC
We can stop here because a partition such as "BC | AD" is equivalent to "AD | BC"; that is, it doesn't matter which set is on the left and which is on the right. Also, order does not matter within a set, so that on the first line, "BCD" could be written as "BDC" or any other permutation.
Strings may be any length. As a further example, given the input "ABCDE", there should be 15 partitions generated:
A | BCDE
B | ACDE
C | ABDE
D | ABCE
E | ABCD
AB | CDE
AC | BDE
AD | BCE
AE | BCD
BC | ADE
BD | ACE
BE | ACD
CD | ABE
CE | ABD
DE | ABC
I'm trying to get a macro to write all possible partitions of a set of elements, where the elements are given as a string of letters.
I've searched and found a small number of posts that refer to _breaking_ a word, line, sentence, etc. into two parts by simply chopping it somewhere in the middle. But I need different _permutations_ of elements at the same time.
The input will be strings of letters with no repeats, and the letters should be partitioned into two (non-empty) sets. Find all such partitions.
Example: Given a cell containg the letters ABCD, the output should be (in two columns)
A | BCD
B | ACD
C | ABD
D | ABC
AB | CD
AC | BD
AD | BC
We can stop here because a partition such as "BC | AD" is equivalent to "AD | BC"; that is, it doesn't matter which set is on the left and which is on the right. Also, order does not matter within a set, so that on the first line, "BCD" could be written as "BDC" or any other permutation.
Strings may be any length. As a further example, given the input "ABCDE", there should be 15 partitions generated:
A | BCDE
B | ACDE
C | ABDE
D | ABCE
E | ABCD
AB | CDE
AC | BDE
AD | BCE
AE | BCD
BC | ADE
BD | ACE
BE | ACD
CD | ABE
CE | ABD
DE | ABC