I'm trying to make a application where you start from one number say in my example
5 then another that number is a bunch of bits 1 and 0's that represent weather the next number is greater then or less then the previous number.
What I'm trying to do is get all the possible combinations of valid fitting numbers.
To do all this I'm trying to generate a tree structure for all possible combinations and only collect those combinations which keep getting longer and longer while getting rid of all the combinations which hit dead-end's in the end I'd like to have all the combinations which are the same length as the number of greater then's and less then's.
I attempted to do the tree structure myself and started to get very confused with how I use it in relation to childerns.
Here is the code I got.
5 then another that number is a bunch of bits 1 and 0's that represent weather the next number is greater then or less then the previous number.
What I'm trying to do is get all the possible combinations of valid fitting numbers.
To do all this I'm trying to generate a tree structure for all possible combinations and only collect those combinations which keep getting longer and longer while getting rid of all the combinations which hit dead-end's in the end I'd like to have all the combinations which are the same length as the number of greater then's and less then's.
I attempted to do the tree structure myself and started to get very confused with how I use it in relation to childerns.
Here is the code I got.
vb.net Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click makeTreeStruct() End Sub Public Enum Operation LessThan = 0 GreaterThan = 1 End Enum Public Class ParentNode Public value As Byte Public Sub New(ByVal value As Byte) Me.value = value End Sub End Class Public Sub makeTreeStruct() 'Dim actualNumbers() As Byte = {5, 6, 1, 9, 7, 3, 8, 2, 4, 10} Dim actualNumberList As New List(Of Byte) actualNumberList.AddRange({5, 6, 1, 9, 7, 3, 8, 2, 4, 10}) Dim ListofGTLT() As Byte = {1, 0, 1, 0, 0, 1, 0, 1, 1} Dim nodeIdCount As Byte = 0 Dim tmpNumbersUsed As New List(Of Byte) Dim tmpId As Integer = 0 Dim firstNumber As Byte = actualNumberList(0) Dim possibleNumbersToUse As New List(Of Byte) Dim numbersAlreadyUsed As New List(Of Byte) For currentLevel = 0 To UBound(ListofGTLT) If currentLevel = 0 Then 'Generates Level 0 of all possible values in the first offset. possibleNumbersToUse = getPossibleNumbersForFirstByte(ListofGTLT(currentLevel), firstNumber, Nothing, 10) Dim parentNode As ParentNode 'Generates parent nodes of all possible values in the first offset. For Each possibleNumber As Byte In possibleNumbersToUse parentNode = New ParentNode(possibleNumber) parentNodes.Add(tmpId, parentNode) tmpId += 1 Next Else possibleNumbersToUse.Clear() numbersAlreadyUsed.Clear() Dim pair As KeyValuePair(Of Integer, ParentNode) For Each pair In parentNodes possibleNumbersToUse = getPossibleNumbersForNextByte(ListofGTLT(currentLevel), pair.Value, pair.Key, firstNumber, 10) tmpId = 0 For Each possibleNumber As Byte In possibleNumbersToUse If currentLevel = 1 Then pair.Value.childern.Add(tmpId, New ParentNode(possibleNumber)) ElseIf currentLevel > 1 Then Dim howMuchChildernIn As Long = currentLevel - 1 Dim lastChild As ParentNode If pair.Value.childern.Count > 0 Then lastChild = pair.Value.childern(tmpId) While howMuchChildernIn > 0 If lastChild.childern.Count > 0 Then lastChild = lastChild.childern(tmpId) End If howMuchChildernIn -= 1 End While lastChild.childern.Add(tmpId, New ParentNode(possibleNumber)) End If End If tmpId += 1 Next Next End If tmpId = 0 Next End Sub Public Function getPossibleNumbersForNextByte(ByVal op As Operation, ByVal aParent As ParentNode, ByVal index As Integer, ByVal firstNumber As Byte, ByVal totalSize As Long) As List(Of Byte) Dim numbersAlreadyUsed As New List(Of Byte) numbersAlreadyUsed.Add(firstNumber) numbersAlreadyUsed.Add(aParent.value) Dim lastOperationNumber As Byte = 0 Dim lastChild As ParentNode While True If aParent.childern.Count > 0 Then lastChild = aParent.childern(index) numbersAlreadyUsed.Add(lastChild.value) moreChildernCheck: If lastChild.childern.Count > 0 Then lastChild = lastChild.childern(index) numbersAlreadyUsed.Add(lastChild.value) GoTo moreChildernCheck End If Exit While Else Exit While End If End While lastOperationNumber = numbersAlreadyUsed(numbersAlreadyUsed.Count - 1) Return getPossibleNumbersForFirstByte(op, lastOperationNumber, numbersAlreadyUsed, totalSize) End Function Public Function getPossibleNumbersForFirstByte(ByVal op As Operation, ByVal operationOf As Byte, ByVal numbersAlreadyUsed As List(Of Byte), ByVal totalSize As Long) As List(Of Byte) Dim possibleNumbers As New List(Of Byte) Dim tempNumber As Integer = -1 While True If op = Operation.LessThan Then tempNumber = IIf(tempNumber = -1, operationOf - 1, tempNumber - 1) ElseIf op = Operation.GreaterThan Then tempNumber = IIf(tempNumber = -1, operationOf + 1, tempNumber + 1) End If If tempNumber < 1 OrElse tempNumber > totalSize Then Exit While End If If numbersAlreadyUsed Is Nothing OrElse numbersAlreadyUsed.Contains(tempNumber) = False Then possibleNumbers.Add(tempNumber) End If End While Return possibleNumbers End Function