Lottery Pairs Formula

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
961
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello everyone,

I wanted to ask if how to calculate how many times a number appears with a second number in a lottery game.
For example, in a 5/30 game how many times does the number 2 appear with the number 1 in the second position?
I know I could create a worksheet with all 142506 possible sets then filter numbers by positions which would result in 3276 total times the number 1 in position 1 and a number 2 in position 2.
How many times the number 1 in position 1 and number 3 in position 3 which is 351?

Thank you.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Could you give a few combination cases of 1 in post 1 and 2 in post 2? and 1 in pos 1 and 3 in post 3?
Is it correct (with dupplicate)
1 2 5 8 10
1 2 20 20 30
and
1 5 3 15 18
1 6 3 30 30

???
 
Upvote 0
Can the following code be changed to calculate Pairs?

StephenCrump post from 2013

Sub Test2()

Dim N As Long, r As Long, lResults() As Long, lTally() As Long, lSmall As Long, lLarge As Long
Dim lTemp As Long, i As Long, j As Long, lFirst As Long
Dim rngPaste As Range

N = 30
r = 5
lSmall = r * (r + 1) / 2
lLarge = r * (2 * N - r + 1) / 2
ReDim lTally(lSmall To lLarge, 1 To N - r + 2)
For i = lSmall To lLarge
lTally(i, 1) = i
Next i

Set rngPaste = Range("A1")
On Error Resume Next
Range("Tallies").Clear
On Error GoTo 0
With rngPaste
.Value = "Sum"
.Offset(, 1).Value = "Frequencies"
With .Offset(1, 1).Resize(, UBound(lTally, 2) - 1)
.Formula = "=Column()-Column(" & rngPaste.Address(, True) & ")"
.NumberFormat = "0"" first"""
End With
.Resize(2).EntireRow.Font.Bold = True
End With

For lFirst = 1 To N - r + 1

lResults = GetCombinations(N - lFirst, r - 1)

For i = 1 To UBound(lResults)
lTemp = 0
For j = 1 To r - 1
lTemp = lTemp + lResults(i, j)
Next j
lTally(lTemp + r * lFirst, 1 + lFirst) = lTally(lTemp + r * lFirst, 1 + lFirst) + 1
Next i

Next lFirst

With rngPaste
.Resize(lLarge - lSmall + 3, UBound(lTally, 2)).Name = "Tallies"
.Offset(2).Resize(lLarge - lSmall + 1, UBound(lTally, 2)).Value = lTally
End With

End Sub

Function GetCombinations(lNumber As Long, lNoChosen As Long) As Long()

Dim lOutput() As Long, lCombinations As Long
Dim i As Long, j As Long, k As Long

lCombinations = WorksheetFunction.Combin(lNumber, lNoChosen)
ReDim lOutput(1 To lCombinations, 1 To lNoChosen)

For i = 1 To lNoChosen
lOutput(1, i) = i
Next i

For i = 2 To lCombinations
For j = 1 To lNoChosen
lOutput(i, j) = lOutput(i - 1, j)
Next j
For j = lNoChosen To 1 Step -1
lOutput(i, j) = lOutput(i, j) + 1
If lOutput(i, j) <= lNumber - (lNoChosen - j) Then Exit For
Next j
For k = j + 1 To lNoChosen
lOutput(i, k) = lOutput(i, k - 1) + 1
Next k
Next i

GetCombinations = lOutput

End Function
 
Upvote 0
Hello everyone,

I wanted to ask if how to calculate how many times a number appears with a second number in a lottery game.
For example, in a 5/30 game how many times does the number 2 appear with the number 1 in the second position?
I know I could create a worksheet with all 142506 possible sets then filter numbers by positions which would result in 3276 total times the number 1 in position 1 and a number 2 in position 2.
How many times the number 1 in position 1 and number 3 in position 3 which is 351?

Thank you.
Hello ststern45, may the link below help


Regards,
Moti
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top