Hi everybody,
I'm stuck in a problem. Suppose that we've a string array Flags() =
{'R' , 'CPNv' , 'ANviV' , 'CPNv' , 'rN!' , 'pN'}. There are 4 x
5 x 4 x 3 x 2 = 480 possible combinations or paths if we consider each
char as a node of Tree. What I want is an other array of string
Combinations(480) that can store each combination of Flags() which are
RCACrp
RCACrN
RCACNp
RCACNN
RCAC!p
RCAC!N
.
.
.
RvVv!N 480th combination.
such as Combinations(0) = RCACrp, Combinations(1) = RCACrN,
Combinations(2) = RCACNp, Combinations(3) = RCACNN, Combinations(4) =
RCAC!p, Combinations(5) = RCAC!N.
I've also posted my effort as a function FlagsCombinations() below. It
is a recursion based function which uses an integer var Level as index
of Flags() and integer m as index of combinations. I used msgboxes for
debugging. Please try to understand and solve in IDE to avoid
complexity
Public Function FlagsCombinations(ByRef Flags() As String, ByRef
Combinations() As String, ByVal Level As Integer, ByRef m As Integer)
As Integer
If Level > Flags.GetUpperBound(0) Then
Return 0 ' Back from above
Else
For Each ch As Char In Flags(Level)
Combinations(m) = Combinations(m) & ch
' MsgBox(Combinations(m) & " - R CPNv ANviV
CPNv rN! pN - " & m)
FlagsCombinations(Flags, Combinations, Level + 1, m)
If Combinations(m).Chars(0) = "`" Then '''''To check
if the loop ended or back from above
Combinations(m) = Combinations(m).Substring(1)
Combinations(m) = Combinations(m - 1).Substring(0,
Combinations(m - 1).LastIndexOf(ch))
Else
If Flags(Level).IndexOf(ch) < Flags(Level).Length
- 1 Then
Combinations(m + 1) =
Combinations(m).Substring(0, Combinations(m).LastIndexOf(ch))
Else
'MsgBox(ch & " is last char of level " &
Level) 'just to check the condition
End If
m = m + 1
End If '''''''''
Next
Combinations(m) = "`" & Combinations(m) 'Adding a char
( ` ) means loop is ended.
End If
Return 0
End Function
--
Subscription settings:
http://groups.google.com/group/dotnetdevelopment/subscribe?hl=en