Setup¶

In [1]:
import math
import numpy as np
import pandas as pd

Constants and Helpers¶

In [2]:
def getP(N):
    '''
    Given the number of students in line, returns the
    probability the Nth student will be in Graphindor.
    '''
    
    p = (3**(N-1) - (-1)**(N-1)) / (4 * 3**(N-1))
    return(p)



def napSort(N) :
    '''
    Given the number of students in line, returns a list of
    tuples (n, p) where n is the number of students from 2 to
    N and p is the corresponding probability that you will be
    placed in Graphindor after hearing 'Graphinoor' being yelled.
    '''
    
    wakeup = []

    cum = 0
    #You are the Nth student.
    for s in range(1, N):

        if s > 1:
            cum = (s-1) * cum

        
        #Your probability is complementary to that of the the person immediately before you.
        cum += (1-getP(s-1))
        cum = cum / s
        wakeup.append((s+1, cum))
   
    return(wakeup)
In [3]:
napSort(5000)[4918:4923]
Out[3]:
[(4920, 0.7498856474893264),
 (4921, 0.7498856707317065),
 (4922, 0.7498856939646406),
 (4923, 0.7498857171881341),
 (4924, 0.749885740402193)]
In [4]:
print(1-getP(8))
0.7498856881572931

Rohan Lewis¶

2024.11.11¶