View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Function for combinations

on 1/19/2012, Robert Crandal supposed :
"GS" wrote in message ...

This smacks of Lottery Wheeling. My advice is to use an array for the

combinations and use its index for the identifier.


For now, suppose that you do NOT have the full list of combos stored in
an array. Suppose I gave you the following 5-combination as input:

"15 23 26 29 40"

Can you think of a good algorithm or scheme for computing the index
number of this combination??? I'm looking for ways to assign unique
identifiers for ANY general combination that might involve N numbers
chosen K at a time. Does that make sense??

Thanks for your help again everyone.


Using an array index will always give you a unique ID. You can also use
a Collection object's 'Key', or the Scripting.Dictionary's 'Key' since
both of those will always be unique because they will raises an error
if you try to add dupes. (**Note** that VB's/VBA's Collection will
process considerably faster than using Scripting's Dictionary) In any
case, you need to increment a counter to create unique keys and so this
brings us back to using an array. Possibly, you'll want to use a 1
based array rather than zero based. I use zero based because my
wheeling combos are stored in ranges where the first cell is the wheel
config, which always occupies array(0) so ticket numbering starts at
array(1) on up to the UBound. So an array with UBound of 42 contains 43
elements; 0 + 42 tickets.

The wheeling algorithms I use are the most popular used for 5+ odds,
and are publicly available online. Just google "lotto wheels". There
are many other configurations for various odds, though.

How they work is for a given set of numbers (say 12, for example) how
many 5, 6, or 7 number combinations can be created to return the odds
using only the 12 numbers in the set. Sets to be wheeled can contain
any number of numbers (I only use 16 max), and resulting combinations
can contain any number of the numbers in the set. For example, you can
generate 5 number combos using 20 number sets. The more numbers in a
set the more combos can be generated. Depending on this criteria, the
number of combos could be in the thousands if you want every possible
combination. To get an idea of the magnitude, check out the odds of a
49 number lottery that draws 6 or even 7 numbers per winning ticket.

I don't actually play the lottery, it's just fun to run wheels and
check them against draw histories.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc