By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

Combinations...

P: n/a
Does anyone have any code for doing combinations in VB.net or visual
basic ? I'd like to
be able to get an array of combinations (not permutations) of words from a
base group of words while specifying the number of unique words to be used
in the result set.

For instance if I have the set {cat dog fish snake} I'd like to be able
to get back a result array of all possible combinations (not permutations)
of X number of words from my base set. For example, all possible
combinations of any 3 words from the base set above would be :

{cat dog fish}
{cat dog snake}
{cat fish snake}
{dog fish snake}

Ideally, I would like to be able to get a result array back with Y known
words in it. For example, if I wanted all possible combinations of any 3
words from the base set above again, but this time I only wanted resulting
arrays that contained the words cat and snake the resulting array should
look like:

{cat dog snake}
{cat fish snake}

Anybody seen this code or at least the mathematical formulas needed to
implement it?

Thanks!



Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Wed, 6 Aug 2003 23:04:45 -0400, "Jim Hubbard"
<ji**********@hotmail.com> wrote:
Does anyone have any code for doing combinations in VB.net or visual
basic ? I'd like to
be able to get an array of combinations (not permutations) of words from a
base group of words while specifying the number of unique words to be used
in the result set.

For instance if I have the set {cat dog fish snake} I'd like to be able
to get back a result array of all possible combinations (not permutations)
of X number of words from my base set. For example, all possible
combinations of any 3 words from the base set above would be :

{cat dog fish}
{cat dog snake}
{cat fish snake}
{dog fish snake}


Something like this could do the trick :-

Option Explicit: DefObj A-Z

' Combinations : J French 7th Aug 03

Private Sub Command1_Click()
Dim Dest$

Call LS_Combine(3, "", "ABCD", Dest$)
Me.Print Dest$

End Sub

Private Sub LS_Combine(SampleSize%, RootIn$, FullSetIn$, Dest$)
Dim L9%, Root$

' --- At bottom - take result and exit
If SampleSize = 0 Then
Dest$ = Dest$ + RootIn$ + vbCrLf
Exit Sub
End If

' --- For each possible Start Letter
For L9 = 1 To Len(FullSetIn$) - SampleSize + 1
' --- Build Root
Root$ = RootIn$ + Mid$(FullSetIn$, L9, 1)
' --- Handle Residue
Call LS_Combine(SampleSize% - 1, _
Root$, _
Mid$(FullSetIn$, L9 + 1), _
Dest$)
Next

End Sub

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.