|
-
Jul 11th, 2006, 01:21 AM
#6
Thread Starter
Fanatic Member
Re: Recursive combinations [please help]
 Originally Posted by Bruce Fox
G'Day WH, how are ya.
Wouldn't the math be (in the example at least)
8x7x6x5x4x3x2x1 (being a range from 1-8)
So that something simple like A,B,C (an Array of 3 elements) yould yeild:
ABC
ACB
BAC
BCA
CAB
CBA
Is that theory correct (if so I have seen it posted here before)?
No, no, no. The idea is to get combinations, not permutations (if I'm using those words right). ABC is the same as ACB as far as I'm concerned. I have an array of numbers. I need to find the best combination of those numbers so that the some of the combination gets closest to a target value. The sum of A+B+C would be the same as the sum of A+C+B. So I need exclusive combinations. And I need every combination or every length. The array might have 8 numbers, but the best combination might consist of only two of those numbers, or only one, or all 8.
I think I'm getting close with the code below, but I'm not sure how to work in the array.
VB Code:
Sub DooDah()
For x = 1 To 3
Combo "", 0, x, 1, 4
Next x
End Sub
Sub Combo(sPrefix, lDepth, lLen, lMin, lMax)
For i = lMin To lMax
If lDepth = (lLen - 1) Then
Debug.Print sPrefix & i
Else
Combo sPrefix & i, lDepth + 1, lLen, i + 1, lMax + 1
End If
Next i
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|