Here is the code for the permutations, note that it prints to the debug window and not all values will be posted there as it maxes out at around 255 lines of text (or something like that). It get around this fill an array instead of printing to the debug window. It is easier to follow the logic without this extra overhead.
VB Code:
Option Explicit Private Sub Command1_Click() Call Shuffle("1,2,3,4,5,6,7,8") End Sub Sub Shuffle(ByVal s As String) Dim a As Variant Dim b As Long Dim c As String Dim i As Long Dim j As Long a = Split(s, ",") For i = 0 To 7 b = i For j = 0 To 5 If b > 7 Then b = 0 c = c & a(b) b = b + 1 Next j Call Permutations(c) c = "" Next i End Sub Sub Permutations(s As String, Optional sLeading As String) Dim i As Long For i = 1 To Len(s) If Len(s) > 2 Then Permutations Right$(s, Len(s) - 1), sLeading & Left$(s, 1) Else Debug.Print sLeading & s End If s = Right$(s, Len(s) - 1) & Left$(s, 1) Next End Sub




Reply With Quote