---
# 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
import numpy as np
res_frame = pd.DataFrame(index=[1], columns=np.arange(0,100,1))
for b in range(20):
    candidate_points = np.random.random(size=100)*10
    for R in range(100):
        best_candidate = np.argmax(candidate_points)-R
        candidate_upd = candidate_points[R:]
        best_rejected = np.max(candidate_points[:R])
        if candidate_upd<= best_rejected:
        selected =np.where(candidate_upd>best_rejected)[0][0]
        res_frame.loc[1,R] += (selected == best_candidate)

return np.argmax(res_frame/20)
        
        
        
        
```      
