Skip to content
Advertisement

Unexpected values when simulating the Secretary problem

I was trying to simulate the Secretary problem in JS, expecting to get a value of 1/e (~37%), but what I am getting is much less (~10%), and it was changing, increasing people would decrease it.

This is what I tried, I think the error might be the let x=new Array(people).fill(0).map(e=>Math.random()) . I was expecting 37%, but got ~10%

JavaScript

I also plotted some of the data on desmos here.

Advertisement

Answer

I don’t understand how you count the number of successful trials to compute the probability. Try to replace the counting logic as follows.

JavaScript

Basically, your trial is successful only when the first higher than min value is the total maximum. This gives values close to 1/e*100 for me.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement