In [1]:
import math
In [44]:
# "Select five numbers between 1 and 69 for the white balls, then select one number between 1 and 26 for the red Powerball."
math.comb(69,5) * (26/25)
# https://www.powerball.com/powerball-prize-chart
# they state the odds of 5 ball match at "1 in 11,688,053.52"
Out[44]:
11688053.52
In [37]:
# 5 ball + power ball, "1 in 292,201,338.00"
math.comb(69,5)*26
Out[37]:
292201338
In [8]:
# 4 ball match, officially "1 in 36,525.17"
# they pick 5 numbers from a set of 69, what's the chance I randomly pick one of them? 5/69
# my first guess was right, what's the chance I get one of the remaining four?
# my 1,2 guesses were right, one of the remaining three?
# my 1,2,3 guesses good, one of remaining two?
# my 1,2,3,4 guesses good, but not the fifth?
1/((5/69)*(4/68)*(3/67)*(2/66)*(64/65))
Out[8]:
175601.765625
In [30]:
# 4 ball match, officially "1 in 36,525.17"
# okay, but what if the {1..5}nth guess is the wrong one, but the other 4 are right?
1/(((5/69)*(4/68)*(3/67)*(2/66)*(64/65)) +
 ((5/69)*(4/68)*(3/67)*(64/66)*(2/65)) +
 ((5/69)*(4/68)*(64/67)*(3/66)*(2/65)) +
 ((5/69)*(64/68)*(4/67)*(3/66)*(2/65)) +
 ((64/69)*(5/68)*(4/67)*(3/66)*(2/65)))
Out[30]:
35120.353124999994
In [45]:
def chooseWithOrderEnum(they, n, without=None):
    if n == 1:
        for x in they:
            if without and x in without:
                continue
            yield (x,)
        return
    if without is None:
        without = []
    for x in they:
        if without and x in without:
            continue
        without.append(x)
        for subchoice in chooseWithOrderEnum(they, n-1, without):
            yield (x,) + subchoice
        without.pop()
def chooseWithoutOrderEnum(they, n):
    if n == 0:
        return
    if n == 1:
        for x in they:
            yield (x,)
        return
    pos = 0
    while True:
        if len(they) - pos == n:
            yield tuple(they[pos:])
            return
        chosen = they[pos]
        for rest in chooseWithoutOrderEnum(they[pos+1:], n-1):
            yield (chosen,) + rest
        pos += 1
for wat in chooseWithoutOrderEnum((1,2,3,4,5), 2):
    print(wat)
(1, 2)
(1, 3)
(1, 4)
(1, 5)
(2, 3)
(2, 4)
(2, 5)
(3, 4)
(3, 5)
(4, 5)
In [46]:
def pbprob(hit, pbhit, explainOut=None):
    explainParts = []
    totalProb = 0.0
    for hits in chooseWithoutOrderEnum((1,2,3,4,5), hit):
        hitRemain = 5
        missRemain = 64
        allRemain = 69
        thisProb = 1.0
        exprParts = []
        for pos in (1,2,3,4,5):
            if pos in hits:
                thisProb *= (hitRemain / allRemain)
                exprParts.append(f"({hitRemain}/{allRemain})")
                hitRemain -= 1
                allRemain -= 1
            else:
                thisProb *= (missRemain / allRemain)
                exprParts.append(f"({missRemain}/{allRemain})")
                missRemain -= 1
                allRemain -= 1
        if pbhit:
            thisProb *= (1/26.0)
            exprParts.append("(1/26)")
        else:
            thisProb *= (25.0/26.0)
            exprParts.append("(25/26)")
        explainParts.append("(" + "*".join(exprParts) + ")")
        totalProb += thisProb
    explain = " +\n".join(explainParts)
    print(explain)
    return totalProb
# pick 4, "1 in 36,525.17"
1/pbprob(4, False)
((5/69)*(4/68)*(3/67)*(2/66)*(64/65)*(25/26)) +
((5/69)*(4/68)*(3/67)*(64/66)*(2/65)*(25/26)) +
((5/69)*(4/68)*(64/67)*(3/66)*(2/65)*(25/26)) +
((5/69)*(64/68)*(4/67)*(3/66)*(2/65)*(25/26)) +
((64/69)*(5/68)*(4/67)*(3/66)*(2/65)*(25/26))
Out[46]:
36525.16724999999
In [39]:
# pick 1 + pb, "1 in 91.98"
1/pbprob(1, True)
((5/69)*(64/68)*(63/67)*(62/66)*(61/65)*(1/26)) +
((64/69)*(5/68)*(63/67)*(62/66)*(61/65)*(1/26)) +
((64/69)*(63/68)*(5/67)*(62/66)*(61/65)*(1/26)) +
((64/69)*(63/68)*(62/67)*(5/66)*(61/65)*(1/26)) +
((64/69)*(63/68)*(62/67)*(61/66)*(5/65)*(1/26))
Out[39]:
91.97745523910251
In [40]:
# pick 2 + pb, "1 in 701.33"
1/pbprob(2, True)
((5/69)*(4/68)*(64/67)*(63/66)*(62/65)*(1/26)) +
((5/69)*(64/68)*(4/67)*(63/66)*(62/65)*(1/26)) +
((5/69)*(64/68)*(63/67)*(4/66)*(62/65)*(1/26)) +
((5/69)*(64/68)*(63/67)*(62/66)*(4/65)*(1/26)) +
((64/69)*(5/68)*(4/67)*(63/66)*(62/65)*(1/26)) +
((64/69)*(5/68)*(63/67)*(4/66)*(62/65)*(1/26)) +
((64/69)*(5/68)*(63/67)*(62/66)*(4/65)*(1/26)) +
((64/69)*(63/68)*(5/67)*(4/66)*(62/65)*(1/26)) +
((64/69)*(63/68)*(5/67)*(62/66)*(4/65)*(1/26)) +
((64/69)*(63/68)*(62/67)*(5/66)*(4/65)*(1/26))
Out[40]:
701.3280961981567
In [41]:
# pick 3, "1 in 579.76"
1/pbprob(3, False)
((5/69)*(4/68)*(3/67)*(64/66)*(63/65)*(25/26)) +
((5/69)*(4/68)*(64/67)*(3/66)*(63/65)*(25/26)) +
((5/69)*(4/68)*(64/67)*(63/66)*(3/65)*(25/26)) +
((5/69)*(64/68)*(4/67)*(3/66)*(63/65)*(25/26)) +
((5/69)*(64/68)*(4/67)*(63/66)*(3/65)*(25/26)) +
((5/69)*(64/68)*(63/67)*(4/66)*(3/65)*(25/26)) +
((64/69)*(5/68)*(4/67)*(3/66)*(63/65)*(25/26)) +
((64/69)*(5/68)*(4/67)*(63/66)*(3/65)*(25/26)) +
((64/69)*(5/68)*(63/67)*(4/66)*(3/65)*(25/26)) +
((64/69)*(63/68)*(5/67)*(4/66)*(3/65)*(25/26))
Out[41]:
579.7645595238095
In [42]:
# pick 3 + pb, "1 in 14,494.11"
1/pbprob(3, True)
((5/69)*(4/68)*(3/67)*(64/66)*(63/65)*(1/26)) +
((5/69)*(4/68)*(64/67)*(3/66)*(63/65)*(1/26)) +
((5/69)*(4/68)*(64/67)*(63/66)*(3/65)*(1/26)) +
((5/69)*(64/68)*(4/67)*(3/66)*(63/65)*(1/26)) +
((5/69)*(64/68)*(4/67)*(63/66)*(3/65)*(1/26)) +
((5/69)*(64/68)*(63/67)*(4/66)*(3/65)*(1/26)) +
((64/69)*(5/68)*(4/67)*(3/66)*(63/65)*(1/26)) +
((64/69)*(5/68)*(4/67)*(63/66)*(3/65)*(1/26)) +
((64/69)*(5/68)*(63/67)*(4/66)*(3/65)*(1/26)) +
((64/69)*(63/68)*(5/67)*(4/66)*(3/65)*(1/26))
Out[42]:
14494.113988095236
In [43]:
# pick 4 + pb, "1 in 913,129.18"
1/pbprob(4, True)
((5/69)*(4/68)*(3/67)*(2/66)*(64/65)*(1/26)) +
((5/69)*(4/68)*(3/67)*(64/66)*(2/65)*(1/26)) +
((5/69)*(4/68)*(64/67)*(3/66)*(2/65)*(1/26)) +
((5/69)*(64/68)*(4/67)*(3/66)*(2/65)*(1/26)) +
((64/69)*(5/68)*(4/67)*(3/66)*(2/65)*(1/26))
Out[43]:
913129.18125
In [51]:
# pb only, nothing else "1 in 38.32"
p_pbOnly = (((64/69)*(63/68)*(62/67)*(61/66)*(60/65))*(1/26))
1/p_pbOnly
Out[51]:
38.32393968295938
In [52]:
# expected value of a $2 ticket, not including jackpot
(p_pbOnly*4) + (4*pbprob(1,True)) + (7*pbprob(2,True)) + (7*pbprob(3,False)) + (100*pbprob(3,True)) + (100*pbprob(4,False)) + (50000 * pbprob(4,True)) + (1000000/(math.comb(69,5) * (26/25)))
((5/69)*(64/68)*(63/67)*(62/66)*(61/65)*(1/26)) +
((64/69)*(5/68)*(63/67)*(62/66)*(61/65)*(1/26)) +
((64/69)*(63/68)*(5/67)*(62/66)*(61/65)*(1/26)) +
((64/69)*(63/68)*(62/67)*(5/66)*(61/65)*(1/26)) +
((64/69)*(63/68)*(62/67)*(61/66)*(5/65)*(1/26))
((5/69)*(4/68)*(64/67)*(63/66)*(62/65)*(1/26)) +
((5/69)*(64/68)*(4/67)*(63/66)*(62/65)*(1/26)) +
((5/69)*(64/68)*(63/67)*(4/66)*(62/65)*(1/26)) +
((5/69)*(64/68)*(63/67)*(62/66)*(4/65)*(1/26)) +
((64/69)*(5/68)*(4/67)*(63/66)*(62/65)*(1/26)) +
((64/69)*(5/68)*(63/67)*(4/66)*(62/65)*(1/26)) +
((64/69)*(5/68)*(63/67)*(62/66)*(4/65)*(1/26)) +
((64/69)*(63/68)*(5/67)*(4/66)*(62/65)*(1/26)) +
((64/69)*(63/68)*(5/67)*(62/66)*(4/65)*(1/26)) +
((64/69)*(63/68)*(62/67)*(5/66)*(4/65)*(1/26))
((5/69)*(4/68)*(3/67)*(64/66)*(63/65)*(25/26)) +
((5/69)*(4/68)*(64/67)*(3/66)*(63/65)*(25/26)) +
((5/69)*(4/68)*(64/67)*(63/66)*(3/65)*(25/26)) +
((5/69)*(64/68)*(4/67)*(3/66)*(63/65)*(25/26)) +
((5/69)*(64/68)*(4/67)*(63/66)*(3/65)*(25/26)) +
((5/69)*(64/68)*(63/67)*(4/66)*(3/65)*(25/26)) +
((64/69)*(5/68)*(4/67)*(3/66)*(63/65)*(25/26)) +
((64/69)*(5/68)*(4/67)*(63/66)*(3/65)*(25/26)) +
((64/69)*(5/68)*(63/67)*(4/66)*(3/65)*(25/26)) +
((64/69)*(63/68)*(5/67)*(4/66)*(3/65)*(25/26))
((5/69)*(4/68)*(3/67)*(64/66)*(63/65)*(1/26)) +
((5/69)*(4/68)*(64/67)*(3/66)*(63/65)*(1/26)) +
((5/69)*(4/68)*(64/67)*(63/66)*(3/65)*(1/26)) +
((5/69)*(64/68)*(4/67)*(3/66)*(63/65)*(1/26)) +
((5/69)*(64/68)*(4/67)*(63/66)*(3/65)*(1/26)) +
((5/69)*(64/68)*(63/67)*(4/66)*(3/65)*(1/26)) +
((64/69)*(5/68)*(4/67)*(3/66)*(63/65)*(1/26)) +
((64/69)*(5/68)*(4/67)*(63/66)*(3/65)*(1/26)) +
((64/69)*(5/68)*(63/67)*(4/66)*(3/65)*(1/26)) +
((64/69)*(63/68)*(5/67)*(4/66)*(3/65)*(1/26))
((5/69)*(4/68)*(3/67)*(2/66)*(64/65)*(25/26)) +
((5/69)*(4/68)*(3/67)*(64/66)*(2/65)*(25/26)) +
((5/69)*(4/68)*(64/67)*(3/66)*(2/65)*(25/26)) +
((5/69)*(64/68)*(4/67)*(3/66)*(2/65)*(25/26)) +
((64/69)*(5/68)*(4/67)*(3/66)*(2/65)*(25/26))
((5/69)*(4/68)*(3/67)*(2/66)*(64/65)*(1/26)) +
((5/69)*(4/68)*(3/67)*(64/66)*(2/65)*(1/26)) +
((5/69)*(4/68)*(64/67)*(3/66)*(2/65)*(1/26)) +
((5/69)*(64/68)*(4/67)*(3/66)*(2/65)*(1/26)) +
((64/69)*(5/68)*(4/67)*(3/66)*(2/65)*(1/26))
Out[52]:
0.31986865166236855
In [ ]: