---
# System prepended metadata

title: Problem 1

---

# Problem 1

We will see N=100 job candidates whose levels are random between 0 and 10. We see the candidates one-by-one, and after seeing each candidate, we have to make a decision on the spot whether to hire this candidate or not. This decision is irrevocable and we cannot change our mind later! 

Our policy for selecting a candidate is the following:

* Reject the first R candidates, for some value R.
* Then hire the first one we see that is better than the best among the first R.

Write a program that finds the value of R that is _maximizing the probability to hire the best out of the N candidates_ using simulations. 


```python=3.7
def get_candidates():
    return # List of random N values

def policy(R):
    candidates = get_candidates()
    max_score = max(candidates[:R])
    for cand_score in candidates[R+1:]:
        if cand_score > max_score:
            max_score = cand_score
            break
    
    if max_score >= max(candidates):
        return 1
    else:
        return 0

R = 1, ... len(get_candidates())

0, 1, 0

experiment_r = [policy(1) for i in range(10000)]
probab = sum(experiment_r)/sum(r for r [sum(experiment_r)])

probab




```