# Possible Combination Generator in Specific Format

I want to generate a list of all the possible combinations of a given group of characters in a specific format.

1. Each set has four slots with a space between each slot in the following format where * represents a slot:

1. Each slot is separated by a endofline thus two sets would have a format of:

1. The last slot always consists of the character “L”:
• L
1. The other three slots can consist of:

A. A single “-” character (hyphen)
B. A Single “P” character.
C. A single “T” character.
D. A combination of the “P” and “T” character with the “P” always appearing before the “T” whereas the two are combined.
E. The characters should not repeat in each slot thus “PP” and “TT” are not permitted.

1. Examples of valid output:

P P P L
T - P L
PT P - L
P - P L
P P PT L

1. Examples of invalid output:

P - TP L (3rd slot has T before P)
P P P P (last slot is not a L)
P PP T L (second slot uses double P)

1. I would like to add an option to allow 4E above, thus each slot could consist of “PP” or “TT”.

Is there a specific technical name for this format that I can search Google for? I found some online generators for combinations, but none exactly could do what I wanted.

This doesn’t seem like a complicated problem unless I’m missing something (always a possibility). You only need the unique three-way combinations of each possibility since they all end in “L” anyway.

I’m sure there are faster ways to do it, but I’d create an array of all the possibilities (“P”, “T”, “PT”, “PP”, “TT”), then use three embedded loops to create the combinations and add them to a Dictionary. When you’re done, the keys of the Dictionary are all of your combinations.

Something like this:

``````dim source() as string = array( "P", "T", "PT", "PP", "TT" )
dim uniqueDict() as new Dictionary
dim slots( 3 ) as string
slots( 3 ) = "L"
for slot1Index as integer = 0 to source.Ubound
slots( 0 ) = source( slot1Index )
for slot2Index as integer = 0 to source.Ubound
slots( 1 ) = source( slot2Index )
for slot3Index as integer = 0 to source.Ubound
slots( 2 ) = source( slot3Index )
dim combo as string = join( slots, " " )
uniqueDict.Value( combo ) = nil
next
next
next``````

I haven’t tested this.

I took your code as a starting place and this seems to work for a sorted list of combinations.

``````  Dim Source() as String = Array("P", "T", "PT", "-")
Dim Slots(3) as String
Dim Combos(), S as String

Slots(3) = "L"

For Slot1Index as Integer = 0 to Source.Ubound

Slots(0) = Source(Slot1Index)

For Slot2Index as Integer = 0 to Source.Ubound

Slots(1) = Source(Slot2Index)

For Slot3Index as Integer = 0 to Source.Ubound

Slots(2) = Source(Slot3Index)

Combos.Append Join(Slots, " ")

Next

Next

Next

Combos.Sort

S = Join(Combos)
S = ReplaceAll(S, "L ", "L" + EndofLine)

TextArea1.AppendText S``````

Results:

• L
• P L
• PT L
• T L
• P - L
• P P L
• P PT L
• P T L
• PT - L
• PT P L
• PT PT L
• PT T L
• T - L
• T P L
• T PT L
• T T L
P - - L
P - P L
P - PT L
P - T L
P P - L
P P P L
P P PT L
P P T L
P PT - L
P PT P L
P PT PT L
P PT T L
P T - L
P T P L
P T PT L
P T T L
PT - - L
PT - P L
PT - PT L
PT - T L
PT P - L
PT P P L
PT P PT L
PT P T L
PT PT - L
PT PT P L
PT PT PT L
PT PT T L
PT T - L
PT T P L
PT T PT L
PT T T L
T - - L
T - P L
T - PT L
T - T L
T P - L
T P P L
T P PT L
T P T L
T PT - L
T PT P L
T PT PT L
T PT T L
T T - L
T T P L
T T PT L
T T T L

For some strange reason the forum altered my “results” text to show small dots for the first several lines - those don’t actually appear in the results - they are actually hyphens.

That’s how you make a bullet list in a post - put a hyphen-space at the beginning of each line. You could embed your list in `[code]` tags to prevent the forum software from interpreting the hyphens.