Sub AppStart (Args() As String)
' data for combinations
Dim inArray() As Object = Array As Object (7,8,9)
' get combinations - the second value is how long each array will be so below will return a,b,c,d etc
Dim result As List = CalculateCombinationsX(inArray,4)
' print them
printCombinations(result)
End Sub
Sub CalculateCombinationsX(inputArray() As Object,resultSize As Int) As List
Dim resSize As Int = resultSize - 1
Dim c(resultSize) As Int
Dim arLength As Int = inputArray.Length - 1
Dim outputList As List
outputList.Initialize
' initialize the counters **ignore the unused 'thing' message in logs
For Each thing As Object In c
thing = 0
Next
' calculate the combinations
Do While c(0) <> inputArray.Length
Dim cCounter As Int = 0
Dim tempForItem(resultSize) As Object
For Each thingy In c
tempForItem(cCounter) = inputArray(thingy)
cCounter = cCounter + 1
Next
' add to outputList
outputList.Add(tempForItem)
' update & check bounds
c(resSize) = c(resSize) + 1
For t = resSize To 0 Step - 1
If c(t) > arLength And t > 0 Then
c(t) = 0
c(t - 1) = c(t - 1) + 1
Else
Exit
End If
Next
Loop
Return outputList
End Sub
Sub printCombinations(theList As List)
For Each item In theList
Dim dummy() As Object = item ' item is an array so move it to one
Dim outText As String = ""
For Each littleItem In dummy
outText = outText & ", " & littleItem
Next
' pretty output (x, y, z, ...)
Log("(" & outText.SubString(2) & ")") ' substring to jump the ", " added at start
Next
End Sub