Robert Crandal brought next idea :
Suppose I have all possible combinations of a set of 7
numbers chosen 5 at a time. (i.e 7-choose-5). There would
be a set of 21 total combos, which are listed below:
Combo #1) 1-2-3-4-5
Combo #2) 1-2-3-4-6
Combo #3) 1-2-3-4-7
Combo #4) 1-2-3-5-6
Combo #5) 1-2-3-5-7
Combo #6) 1-2-3-6-7
Combo #7) 1-2-4-5-6
Combo #8) 1-2-4-5-7
Combo #9) 1-2-4-6-7
Combo #10 1-2-5-6-7
Combo #11) 1-3-4-5-6
Combo #12) 1-3-4-5-7
Combo #13) 1-3-4-6-7
Combo #14) 1-3-5-6-7
Combo #15) 1-4-5-6-7
Combo #16) 2-3-4-5-6
Combo #17) 2-3-4-5-7
Combo #18) 2-3-4-6-7
Combo #19) 2-3-5-6-7
Combo #20) 2-4-5-6-7
Combo #21) 3-4-5-6-7
I'm trying to devise some sort of function that will associate a
unique identifier for each combination. So, if the combination of
"1 2 3 4 5" is given as input, then my function should return a "1"
(since this is the 1st combo in the list). If "1 3 4 5 7" is given as
input, then the number 12 should be returned, since that is the 12th combo
above. Does that make sense?
I'm basically trying to find a way to generate a unique identifier for any
5-combination that is given as input. It would be nice if the solution could
be applied to a general set of combos, such as N-choose-5.
Does anyone have any ideas? I know this problem isn't really related to
VBA, but I trust the wisdom of everybody here.
Thanks everyone.
Hi Robert,
This smacks of Lottery Wheeling. My advice is to use an array for the
combinations and use its index for the identifier. I have a VBA lottery
wheel generator that assigns 'ticket#' as an identifier based on array
index of the wheel combination, as follows...
vTicketID(i, 0) = "Ticket" & CStr(i + 1)
...being that the array base is zero. This is the first element
(vTicketID(0, 0), for example, of an abreviated wheel that generates 42
(5, 6 or 7 num) combinations with 5/6 odds. In a 7 num draw the UBound
of the 2nd dim of the array is 7, giving an eight element array for the
1st ticket. UBound(vTicketID) is 41.
So.., in your scenario you'd use a 6 element array for each combination
as follows...
For i = LBound(vCombos) To NumTicketsWheeled - 1
vCombos(i, 0) = "Combo #) & CStr(i + 1)
vCombos(i, 1) = vWheel(0)
vCombos(i, 2) = vWheel(1)
vCombos(i, 3) = vWheel(2)
vCombos(i, 4) = vWheel(3)
vCombos(i, 5) = vWheel(4)
Next 'i
Alternatively, you could process each combination separately and write
directly to the worksheet...
Cells(i + 1, 1) = "Combo #" & CStr(i + 1)
Cells(i + 1, 2).Resize(1, 5) = vWheel
HTH
--
Garry
Free usenet access at
http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc