---
# 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 # To discuss

def score(R):
    result = list()
    for i in range(num_candidate_lists):
        candidates = get_candidates()
        
        best_candidate_value = max(candidates)
        
        max_first_R = max(candidates[:R] + [0])
        
        for candidate in candidates[R:]:
            if candidate > max_first_R:
                result.append(candidate == best_candidate_value)
                break
        else:
            result.append(0)

    return np.mean(result)

def find_R(N):
    Rs = range(0, N)
    
    best_score = 0
    for R in Rs:
        score = get_score(R)
        if score >= best_score:
            best_score = score
            best_R = R
    
    return best_R
        
```