View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis Dana DeLouis is offline
external usenet poster
 
Posts: 947
Default Creating character combinations out of a possible set...

...every possible combination is displayed.

Hi. As others have mention, the output is too large.
A newer measure of large might be that you would have to completely fill
3,486,784,401 Columns in Excel 2007. (36^10/2^20) <vbg
In Combinations, one is usually not interested in generating all
combinations. One is usually interested in generating only a few of the
outputs. One might be interested in the 1 millionth item in the list, or
perhaps pick a few items from the list at Random.
It is usually more efficient to generate the combinations as needed. The
function name usually goes by the name UnRank...(ie UnRankCombinations, or
something similar for your example)

The code below just demo's how this might be done for your 3 character
example.
Excel vba can easily find the 2456158341262976 th item from your 10
character example, but it requires a little modification.

Again, this is just a simple example...

Sub TestIt()
Debug.Print UnRank(1) 'First item in list
Debug.Print UnRank(46656)'Last item in list
Debug.Print UnRank(1372)' the 1372 th item in list
End Sub

Returns:
000
ZZZ
123

Function UnRank(Num As Double) As String
Dim n As Double
Dim Block As Double
Dim j As Long
Dim M As Double
Dim s(0 To 35) As String
Const k As Double = 36

For n = 0 To 35
s(n) = Chr((n + 48) - 7 * (n 9))
Next n

'// Note: First item is 000
n = Num - 1
Block = k ^ 2

For j = 2 To 0 Step -1
M = Int(n / Block)
UnRank = UnRank & s(M)
n = n - M * Block
Block = Block / k
Next j
End Function

--
HTH :)
Dana DeLouis
Windows XP & Office 2003


wrote in message
ups.com...
Hey! Here is the problem...I can't figure out how to make it so every
possible combination of a series of letters (A-Z) and Numbers (0-9) is
displayed I saw someones code to make it possible for three characters
but I am looking to do it with like 10 characters...The code I saw was
this...

Sub comboo()
Dim s(36) As String
For i = 0 To 9
s(i) = Chr(i + 48)
Next
For i = 10 To 36
s(i) = Chr(i + 55)
Next


k = 1
For i = 0 To 35
For j = 0 To 35
For l = 0 To 35
Cells(k, "A").Value = s(i) & s(j) & s(l)
k = k + 1
Next
Next
Next
End Sub

Any ideas? Any help is much appreciated!!