Home |
Search |
Today's Posts |
#10
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Certainly it was a feeble attempt to weaken the odds. Question was why a
draw totaling 138 was so frequent. It beats 150 for instance which should be more frequent. If you are going to pick 6 numbers and live with it forever then choose the best odds. Backgammon is won that way. "Mike H" wrote: Just for fun, another way, perhaps a bit faster: Actually no not a 'bit' faster it's a walkover, seconds as opposed to several minutes. Excellent. Mike "JE McGimpsey" wrote: Just for fun, another way, perhaps a bit faster: Public Sub test() Dim vArr As Variant vArr = PickSixToTotal(52, 138) With ActiveSheet.Range("A1") If IsArray(vArr) Then With .Resize(UBound(vArr, 1), UBound(vArr, 2)) .Clear .Value = vArr End With Else .Value = vArr End If End With End Sub Public Function PickSixToTotal( _ ByVal MaxNum As Long, _ ByVal Target As Long, _ Optional ByVal MaxRows As Long = 50000#) As Variant Const sp As String = "," Dim vArr As Variant Dim nCol As Long Dim nCount As Long Dim nCum As Long Dim n1 As Long, n2 As Long, n3 As Long Dim n4 As Long, n5 As Long, n6 As Long Dim n12 As Long, n123 As Long, n1234 As Long If Target < 21 Or Target (6 * MaxNum - 15) Then PickSixToTotal = "Target Out of Range" Exit Function End If nCol = 1 nCount = 1 ReDim vArr(1 To MaxRows, 1 To nCol) For n1 = 1 To MaxNum - 5 If (6 * n1 + 15) <= Target And _ (n1 + 5 * MaxNum - 10) = Target Then For n2 = n1 + 1 To MaxNum - 4 n12 = n1 + n2 If (n1 + 5 * n2 + 10) <= Target And _ (n12 + 4 * MaxNum - 6) = Target Then For n3 = n2 + 1 To MaxNum - 3 n123 = n12 + n3 If (n12 + 4 * n3 + 6) <= Target And _ (n123 + 3 * MaxNum - 3) = Target Then For n4 = n3 + 1 To MaxNum - 2 n1234 = n123 + n4 If (n123 + 3 * n4 + 3) <= Target And _ (n1234 + 2 * MaxNum - 1) = Target Then For n5 = n4 + 1 To MaxNum - 1 n6 = Target - n1234 - n5 If n6 <= n5 Then Exit For If n6 <= MaxNum Then vArr(nCount, nCol) = n1 & sp & n2 & sp & _ n3 & sp & n4 & sp & n5 & sp & n6 If nCount = MaxRows Then nCol = nCol + 1 nCount = 1 ReDim Preserve vArr(1 To MaxRows, 1 To nCol) Else nCount = nCount + 1 End If End If Next n5 End If Next n4 End If Next n3 End If Next n2 End If Next n1 PickSixToTotal = vArr End Function In article , Mike H wrote: Hi, An interesting Sunday afternoon exercise. Firstly, you will need to be quite wealthy to cover all of the 156004 combinations that add up to 138. To generate them use an empty worksheet and put the numbers 1 - 49 in column A starting in A1. Then right click the sheet tab, view code and paste this in and run it and then make a cup of tea because it took several minutes to run on my PC. P.S. It would be unwise to press the print button unless you have lots of paper!! Sub thelottery() Count = 1 col = 2 lastrow = Range("A65536").End(xlUp).Row Set myRange = Range("A1:A" & lastrow) For Each c In myRange numbers = numbers + 1 Next Dim n(49) For p = 1 To numbers n(p) = Cells(p, 1).Value Next For i = 1 To numbers For j = 1 To numbers If j <= i Then GoTo 100 For k = 1 To numbers If k <= j Then GoTo 200 For l = 1 To numbers If l <= k Then GoTo 300 For m = 1 To numbers If m <= l Then GoTo 400 For o = 1 To numbers If o <= m Then GoTo 500 For x = 1 To numbers If i = x Then firstno = n(x) Next For x = 1 To numbers If j = x Then secondno = n(x) Next For x = 1 To numbers If k = x Then thirdno = n(x) Next For x = 1 To numbers If l = x Then fourthno = n(x) Next For x = 1 To numbers If m = x Then fifthno = n(x) Next For x = 1 To numbers If o = x Then sixthno = n(x) Next If firstno + secondno + thirdno + fourthno + fifthno + sixthno = 138 Then Cells(Count, col).Value = firstno & "," & secondno & "," & thirdno & "," & fourthno & "," & fifthno & "," & sixthno If Count = 65536 Then Count = 1 col = col + 1 Else Count = Count + 1 End If End If 500 Next 400 Next 300 Next 200 Next 100 Next Next Cells(1, 8).Value = Count - 1 End Sub Mike "Kobus" wrote: Question1: How do I calculate the number of combinations in a 49 number 6 ball lottery where every combinations adds up to say: 138. Sum total 279, for instance, can only happen once. Question2: How do I generate these results? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Lottery Model | Excel Worksheet Functions | |||
Lottery check | New Users to Excel | |||
Lottery exercise | Excel Worksheet Functions | |||
lottery drawing | Excel Worksheet Functions | |||
How do I make a lottery checker | New Users to Excel |