I need to generate all combinations (not permutations) in VB .NET, I\'ve been search and all I found is for permutations (some says combinations but when I was try it, all a
This should returns all combinations of said depth in a IEnumerable(Of String)
Function GetCombinations(ByVal depth As Integer, ByVal values As String()) As IEnumerable(Of String)
If depth > values.Count + 1 Then Return New List(Of String)
Dim result = New List(Of String)
For i = 0 To depth - 1
For y = 0 To values.Count - 1
If i = 0 Then
result.Add(values(y))
Else
result.Add(values(i - 1) + values(y))
End If
Next
Next
Return result
End Function
Edit:
Example usage:
Dim data_array As String() = {"1", "2", "3", "4", "5", "6"}
Dim reslt = GetCombinations(2, data_array)