Setup¶

In [1]:
import math
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import StrMethodFormatter as SMF
import seaborn as sns

Constants and Helpers¶

In [2]:
#Let n be the number of sprinters.
#pairsT(n) gives the total number of pairs.
def pairsT(n) :
    p = n * (n-1) / 2
    return(p)

def pairsU(n) :
    p = n * math.log2(n)
    return(p)

#pairsM(n) gives the maximum number of pairs needed to determine the order.
def pairsM(n) :
    
    p = 0
    for i in range(1, n+1) :
        p += math.ceil(math.log2(i))
        
    return(p)


x = list(range(1, 100))
T = [pairsT(t) for t in x]
U = [pairsU(u) for u in x]
M = [pairsM(m) for m in x]



def limitPlot(xmax, ymax, lw, o):
    sns.set()
    fig = plt.figure(figsize = (12, 8))
    ax = fig.add_subplot(111, xlim = (1, xmax), ylim = (1, ymax))


    #3 Scatter Plots.
    ax.scatter(x = x,
               y = T,
               c = "#73D055",
               lw = lw,
               label = "Total Sprinter Pairs")
    
    ax.scatter(x = x,
               y = U,
               c = "#238A8D",
               lw = lw,
               label = "Upper Limit of Pairs to Order")

    ax.scatter(x = x,
               y = M,
               c = "#440154",
               lw = lw,
               label = "Max Pairs to Order")
    
    ax.yaxis.set_major_formatter(SMF('{x:,.0f}'))
    
    #Titles, Axes, & Legend
    ax.set_title("Ordering the Sprinters", fontsize = 24)
    ax.set_xlabel("Sprinters", fontsize = 20)
    ax.set_ylabel("Pairs", fontsize = 20);
    ax.legend(fontsize = '16', loc = 'upper left')
    
    fig.savefig('2024.05.03 Fiddler' + str(o) + '.png');
In [3]:
limitPlot(10, 50, 5, 1)
In [4]:
limitPlot(100, 5000, 1, 2)
Rohan Lewis¶

2024.05.05¶