View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Coverage of a List of Lotto Tickets

If the bonus is just a 7th number drawn from the 49, then this builds the
results you show. A special condition requires special code.

Sub GenNumbers()
Dim start As Double
start = Timer
Dim lngCount(0 To 7) As Long
varray = Array(1, 2, 3, 4, 5, 6, 7)
Dim r As Long
num = 49
For i = 1 To num - 5
For j = i + 1 To num - 4
For k = j + 1 To num - 3
For l = k + 1 To num - 2
For m = l + 1 To num - 1
For n = m + 1 To num
r = r + 1
If True Then
icnt = 0
bBonus = False
For s = 0 To 6
If s < 6 Then
If i = varray(s) Then icnt = icnt + 1
If j = varray(s) Then icnt = icnt + 1
If k = varray(s) Then icnt = icnt + 1
If l = varray(s) Then icnt = icnt + 1
If m = varray(s) Then icnt = icnt + 1
If n = varray(s) Then icnt = icnt + 1
Else
If i = varray(s) Or j = varray(s) Or _
k = varray(s) Or l = varray(s) Or _
m = varray(s) Or n = varray(s) Then
bBonus = True
End If
End If
Next
If icnt < 5 Then
lngCount(icnt) = lngCount(icnt) + 1
ElseIf icnt = 5 And Not bBonus Then
lngCount(icnt) = lngCount(icnt) + 1
ElseIf (icnt = 5 And bBonus) Or _
icnt = 6 Then
lngCount(icnt + 1) = lngCount(icnt + 1) + 1
End If
End If
Next
Next
Next
Next
Next
Next
Debug.Print r
lngsum = 0
For s = 0 To 7
If s = 3 Then lngsum = lngsum + lngCount(s)
If s <= 5 Then
Debug.Print s & " Matches (no bonus): " & lngCount(s)
ElseIf s = 6 Then
Debug.Print s & " Matches (With bonus): " & lngCount(s)
Else
Debug.Print s - 1 & " Matches (no bonus): " & lngCount(s)
End If

Next
Debug.Print "At least 3 matches " & lngsum
Debug.Print (Timer - start) / 60 & " minutes"
End Sub

Produces:
13983816
0 Matches (no bonus): 6096454
1 Matches (no bonus): 5775588
2 Matches (no bonus): 1851150
3 Matches (no bonus): 246820
4 Matches (no bonus): 13545
5 Matches (no bonus): 252
6 Matches (With bonus): 6
6 Matches (no bonus): 1
At least 3 matches 260624
2.39019791666663 minutes

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
Hi Tom,

Thanks for the Reply.
I Don't think I Explained Clearly Enough what I am Hoping to Achieve.
I think if this Exercise can be Achieved, it will make it a Lot Clearer
for me to Understand the Concepts of Number Manipulation Within Code.
The Results Should be for a 6 from 49 with One Bonus Number Drawn which
is ONLY Relevant for the Match 5 :-

0 Matches ( NO Bonus ) Totals = 6,096,454
1 Matches ( NO Bonus ) Totals = 5,775,588
2 Matches ( NO Bonus ) Totals = 1,851,150
3 Matches ( NO Bonus ) Totals = 246,820
4 Matches ( NO Bonus ) Totals = 13,545
5 Matches ( NO Bonus ) Totals = 252
5 + The Bonus Number Totals = 6
6 Matches ( NO Bonus ) Totals = 1
Total = 13,983,816

Thanks for ALL your Help and Time.
All the Best
Paul