Home Archives Search Feed Football Squares How To Use


MLB (Red Sox @ Yankees): Which will OCCUR FIRST in the 1st Inning?


7:05 PM
Hit or Neither Occur
2 Strikouts


Inputs Needed to Solve

approx stikeout per out rate (Price and Happ)
approx hit per AB rate (Red Sox and Yankees)

##### User Estimates #####
strikeout_per_out = float(123+89)/((102+109+1)*3)
hit_per_AB = float(1107+1017)/(4241+4531)
## Inputs Defined in the Problem
period_of_innings = 1
hit = 'H'
Ks_ = 'KK' 

Method to Solve

from numpy.random import choice

def sim_inn(hit_per_AB,strikeout_per_out):
    outs = 0
    sequence = []
    
    while outs < 6:
        AB = choice(['H','O'],1,[hit_per_AB,1-hit_per_AB])
        if AB == 'H':
            sequence.append(AB)
        else:
            outs += 1
            K = choice(['K','no_k'],1,[strikeout_per_out,1-strikeout_per_out])
            if K == 'K':
                sequence.append(K)
    
    ans = ''
    for i in sequence:
        for j in i:
            ans += str(j)
    
            
    return ans

def find_first(sequence):
    _2ks = False
    
    count = 0
    hit_count = 998
    k = 0
    k_count = 999
    end = 0
    
    for i in sequence:
        count += 1
        if i == 'H':
            hit_count = min(count,hit_count)
        else:
            k += 1
            if k == 2:
                k_count = min(k_count,count)
                
    if k_count < hit_count:
        _2ks = True
        
    return _2ks
iterations = 9999
Ks_first = 0

for i in range(iterations):
    inn = sim_inn(strikeout_per_out,hit_per_AB)
    if i < 15:
        print(inn)
    ans = find_first(inn)
    if ans:
        Ks_first += 1
        

p_2Ks_fist = float(Ks_first)/iterations
KKHHKHHKHHHK
KHHHKHHHHKK
HKHHHHHHKKHHHKHHHHHHK
HKK
HHKHHHKKHHKHK
KHKHKHHHHHK
KKHHHK
HKKHHKHHKHK
HHKKHHHKHHHK
HHHKHKHK
KHKHHHKHH
HHHKKKHHHHKK
KHHHHKHK
HHHKHKHHHKHKHK
KKHK

Solution

print("The probability that 2 STRIKEOUTS occur first in the 1st Inning is ~%s" % round(p_2Ks_fist,3))
The probability that 2 STRIKEOUTS occur first in the 1st Inning is ~0.105
Posted on 8/4/2019






← Next post    ·    Previous post →