• Status: Solved
• Priority: Medium
• Security: Public
• Views: 307

# List of possible combinations

I am trying to write some vb.net code that will list all possible combnations of a lst of words.

Currently, I'm interested in the non repeating combination of 4 words "brand", "kind", "size" and "weight".  order is not important.

for example,

I would like to see

brand
brand,kind
brand,kind,size
brand,kind,size,weight

etc

by non repeating I mean for example that
if brand,kind is listed i do not want to see kind,brand

Any ideas???

0
johnnyg123
1 Solution

Commented:
Hi, try this:

Module Module1

Sub Main()

Dim R As String

For I As Integer = 1 To 15

R = String.Empty

R &= IIf(I And 1, "weight,", "")
R &= IIf(I And 1 << 1, "size,", "")
R &= IIf(I And 1 << 2, "kind,", "")
R &= IIf(I And 1 << 3, "brand,", "")

If R.EndsWith(",") Then
R = R.Substring(0, R.Length - 1)
End If

Console.WriteLine(R)
Next

End Sub

End Module
0

Senior .Net DeveloperCommented:
None repeating is easy:

Loop through the array, appending the next word in.

Ex:

Dim x As String() = "r,t".Split(",")

Dim s As String
s = ""
For i As Integer = 0 To x.Length
s = s + x(i)
'output S
Next
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.