Skip to content

Instantly share code, notes, and snippets.

@neila
Last active February 7, 2019 17:32
Show Gist options
  • Save neila/ec40b8385687f0cc6ce95f0022d147cc to your computer and use it in GitHub Desktop.
Save neila/ec40b8385687f0cc6ce95f0022d147cc to your computer and use it in GitHub Desktop.
CS110 4.2 Preclass
import random
import math
import matplotlib.pyplot as plt
import numpy as np
masterinterview = []
masterhire = []
for apps in range(1,1501):
interviewlist = []
hirelist = []
for reps in range(100):
interview = 0 #count interviews
hire = 0 #count hires
best = 0 #current worker's "strength"
cand = [random.random() for i in range(1,apps+1)] #list of candidates with "strengths" from 1 to 100
for i in range(len(cand)):
interview += 1 #count interviews
if cand[i] > best: #if candidate is better than current worker, hire
best = cand[i]
hire += 1 #count hire
interviewlist.append(interview)
hirelist.append(hire)
masterinterview.append(int(np.mean(interviewlist)))
masterhire.append(np.mean(hirelist))
plt.ylabel("Number of hires")
plt.xlabel("Number of candidates")
plt.plot([i for i in range(1,1501)],[math.log(i) for i in range(1,1501)], label = "theoretical estimate")
plt.scatter([i for i in range(1,1501)],masterhire, color = "r", s = 0.4, label = "observed estimate")
plt.legend(loc="lower right")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment