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

M = 1000 #n of simulations
N = 100

samples = [[random.random()*10 for i in range(N)] for j in range(M)] # -> U[0, 1]

best_sample_candiate = [max(i) for i in samples]

best_R_values_counter = {i: 0 for i in range(1, N)}

for sample in samples:
    chosen_values = []
    for R in range(1, N): #from 1 to 99
        best_value_in_R = max(sample[:R])
        
        chosen_value = -1
        for i in range(R+1, N):
            if sample[i] > best_value_in_R:
                chosen_value = sample[i]
                break
    
        chosen_values.append(chosen_value)
    
    best_sample_R_index = 0
    for i in range(1, N-1):
        if chosen_values[i] > chosen_values[best_sample_R_index]
            best_sample_R_index = i
           
    best_R_values_counter[best_sample_R_index] += 1


most_frequent = -1
best_R = -1
for key, value in best_R_values_counter.items():
    if value > most_frequent:
        best_R = key
        most_frequent = value



    
```



# 2. Find Number Pi

## Problem description

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

```python=

```