Public MyDict
Sub GetCombs()
Set MyDict = CreateObject("Scripting.Dictionary")
Call Recur("abcdefghij", 0, "")
Range("A1").Resize(MyDict.Count) = WorksheetFunction.Transpose(MyDict.keys)
End Sub
Sub Recur(chars, depth, sofar)
Dim i As Long
If depth = 7 Then
MyDict.Add sofar, 1
Exit Sub
End If
For i = InStr(chars, Right(sofar, 1)) To Len(chars)
Call Recur(chars, depth + 1, sofar & Mid(chars, i, 1))
Next i
End Sub
Public MyDict
Sub GetCombs()
Set MyDict = CreateObject("Scripting.Dictionary")
Call Recur("abcdefghij", 0, "")
Range("A1").Resize(MyDict.Count) = WorksheetFunction.Transpose(MyDict.keys)
End Sub
Sub Recur(chars, depth, sofar)
Dim i As Long
If depth = 7 Then
MyDict.Add sofar, 1
Exit Sub
End If
For i = InStr(chars, Right(sofar, 1)) To Len(chars)
If Right(sofar, 3) <> String(3, Mid(chars, i, 1)) Then
Call Recur(chars, depth + 1, sofar & Mid(chars, i, 1))
End If
Next i
End Sub
A | B | C | D | E | F | |
1 | 3 | 2 | 1 | Check | Ways | |
2 | 2 | 0 | 1 | 7 | 360 | E2: =COMBIN(10, A2) * COMBIN(10 - A2, B2) * COMBIN(10 - SUM(A2:B2), C2) |
3 | 1 | 2 | 0 | 7 | 360 | |
4 | 1 | 1 | 2 | 7 | 2520 | |
5 | 1 | 0 | 4 | 7 | 1260 | |
6 | 0 | 3 | 1 | 7 | 840 | |
7 | 0 | 2 | 3 | 7 | 2520 | |
8 | 0 | 1 | 5 | 7 | 1260 | |
9 | 0 | 0 | 7 | 7 | 120 | |
10 | Total | 9240 |