Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Calculate the Number of Subsets
Hi Everyone,
This is Lotto Based. There is a System in Lotto called "Wheels". A Lotto Wheeling System is a Special Pattern to Arrange Numbers into Combinations. This System can be Used Over and Over again with Different Numbers. A Lotto Wheel is Constructed in such a way that if the Winning Numbers Fall in the Group of Numbers you have Selected, you will Always have a Winning Combination Somewhere. If for Example, you have a Group of 12 Numbers then the Lotto Wheel you Select should have the Numbers 1-12 Arranged in Sets of Numbers ( Each Set is 6 Numbers ). You then take the Wheel and Substitute your Numbers in the Wheels Pattern and Simply Replace all the 1's in the Pattern with your First Number, all the 2's with your Second Number, all the 3's with your Third Number, etc. All Wheels give a Guarantee. For Example, the Wheel 24,6,3,6,50 Means, there are 24 Different Numbers Used in the Wheel, there are 6 Numbers Drawn, the Guarantee of having 3 Numbers in at Least 1 Combination if ALL the 6 Numbers Drawn are in the Selected 24 Numbers. I have a Set of 6 Number Combinations in Cells "G13:L27" ( the Number of Combinations could be More or Less ). In this Example I am Using a Wheel with 24 Numbers :- 1,3,7,12,15,16 1,4,5,17,20,21 1,8,9,10,19,22 1,13,14,18,23,24 2,3,6,9,21,23 2,10,12,14,16,20 2,11,15,19,20,24 3,4,7,10,18,24 3,5,7,14,17,19 4,6,8,14,15,22 4,9,11,13,16,19 5,10,13,15,17,23 5,11,12,18,21,22 6,8,12,16,17,24 7,8,13,20,22,23 Here is the Code that someone has Kindly Provided which Cycles through ALL Combinations and Compares ALL the Combinations with ALL the Combinations in the Above Wheel. The Below Code Finds the Coverage ( Total Combinations ) of 5 Numbers if 5 Numbers are Matched … Code: Sub test_5() Dim a, dic As Object Set dic = CreateObject("Scripting.Dictionary") a = Range("g13").CurrentRegion.Value For i = 1 To UBound(a, 1) For ii = 1 To 2 For iii = ii + 1 To 3 For iv = iii + 1 To 4 For v = iv + 1 To 5 For vi = v + 1 To 6 z = a(i, ii) & "," & a(i, iii) & a(i, iv) & a(i, v) & a(i, vi) If Not dic.exists(z) Then dic.Add z, Nothing n = n + 1 End If Next vi, v, iv, iii, ii, i Set dic = Nothing Range("O16") = n End Sub … and Produces the Correct Result of 90. How can the Code be Modified to Also Produce the Combinations Covered for the Categories … Matched = Covered Combinations 2 if 5 = 42,504 3 if 5 = 35,720 4 if 5 = 4,140 5 if 5 = 90 ( the Code Already Provides this Result ) … Please. I was Told for the Interpretation of the 3 if 5 Category that you Need to Cycle through ALL 5 Number Combinations that can be Constructed from the Total Numbers Used in the Wheel ( 24 in this Case ). So if the Wheel Contains "x" Unique Numbers, you Need to Cycle through ALL 5 Number Combinations from those "x" Numbers. Then you Need to Scan the Wheel for Each 5 Number Combination Produced and Compare it with Each Line in the Wheel to see if that Line Matches the 5 Number Combination in *EXACTLY* 3 Numbers. If it does, then that Combination of 3 if 5 is Covered and Added to the Total and there is NO Need to Continue to Check for that Particular Combination Any Further. You then go onto the Next Combination to Check and so on Until ALL Combinations have been Cycled through and Checked with the Wheel. I Hope I have Explained this Clear Enough. Many Thanks in Advance. All the Best. Paul *** Sent via Developersdex http://www.developersdex.com *** |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Creating subsets | Excel Discussion (Misc queries) | |||
Manipulating subsets of large datasets | Excel Worksheet Functions | |||
Xcl-create subsets of a set of numbers w/o duplicating the subset | Excel Worksheet Functions | |||
generate all subsets (2^n array) | Excel Programming | |||
Getting subsets of data | Excel Programming |