---
# System prepended metadata

title: 1. Secretary problem by simulation

---

# 1. Secretary problem by simulation

## Problem Description:

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! We want to _maximize the probability to hire the best out of the N candidates_.

To do so, we will implement the following policy:

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

Write a program that decides the optimal threshold R using simulations.


```python=
    import random
    # random.rand() -> [0,1]
    R_min = 3
    R_max = 50
    R_results = [0] * (R_max - R_min)
    
    for R in range(R_min, R_max):
        N = 100
        n_sim = 10
        sim_results = [0] * n_sim

        for j in range(n_sim):
            candidates = [10 * random.rand() for x in range(N)]
            best = 0
            for i in range(R):
                if candidates[i] > best:
                    best = candidates[i]

            hire_ind = 0
            for i in range(R, N):
                if candidates[i] > best:
                    hire_ind = i
                    break

            if hire_ind == 0:
                return('Failed')

            sim_results[j] = max(candidates) - candidates[hire_ind]

        # sim_results = [x / n_sim for x in sim_results]
        R_results[R-R_min] = sum([x == 0 for x in sim_results]) / n_sim
        
    max(R_results)
    R_results.idxmax()
    
```



# 2. Find Number Pi

## Problem description

*Task:* Estimate number PI using only a random generator. 

```python=

```