Setup¶

In [1]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from random import choice as RC
import seaborn as sns

Fiddler Functions¶

In [2]:
def baseballLeague(g, t) :

    """
    Results of baseball League.

    Parameters:
    g - Games played between two teams.
    t - number of teams.
    
    Returns:
    results - dictionary of [wins, losses] for each team.
    """   

    results = {}
    for i in range(1, t+1) :
        results[i] = 0
        
    for a in range(1, t) :
        for b in range(a+1, t+1) :
            for j in range(g) :
                win = RC([a, b])
                if win == a :
                    results[a] += 1
                if win == b :
                    results[b] += 1
                    
    return(results)

def clearAx(ax):
    
    """
    Clear axes.

    Parameters:
    ax - Current ax.
    
    Returns:
    ax - Updated ax.
    """    
    
    ax.spines["top"].set_visible(False)
    ax.spines["right"].set_visible(False)
    ax.spines["bottom"].set_visible(False)
    ax.spines["left"].set_visible(False)
    ax.set_xticks([])
    ax.set_yticks([])
    return(ax)
In [3]:
j = 10000000
total = 0
for i in range(j):
    data = baseballLeague(162, 2)
    total += max(data.values())

print(total/j)
86.0662559
In [5]:
from math import comb as MC

81 + 81*MC(162, 81)/2**162
Out[5]:
86.06987637833755
In [4]:
j = 10000000
total = 0
for i in range(j):
    data = baseballLeague(5, 30)
    total += max(data.values())

print(total/j)
84.9812503
Rohan Lewis¶

2026.07.06¶