Nerd sniped. I couldn't help it. What do you think> :-)
from math import e, floor
from random import randint
def secretary_search(candidates):
"""Rejects first n / e candidates and then selects the first better."""
n_reject = int(floor(len(candidates) / e))
best = max(candidates[:n_reject])
for candidate in candidates[n_reject:]:
if candidate > best:
return candidate
return candidates[-1]
success = 0.0
size = 100
trials = 10000
for _ in range(trials):
candidates = [randint(1, 1000) for _ in range(size)]
success += max(candidates) == secretary_search(candidates)
print success / trials