Skip to Content

The Monty Hall problem in Ruby

Hi all

I just stumbled on this small piece of Ruby code I wrote a couple of years back. It's a Monty Hall problem experiment. Specifically, it determines the relative frequency of winning the car, if the contestant chooses to switch doors.

The probability of winning when switching doors is 2/3, and the program outputs a relative frequency very close to this probability. To get progressively closer, you can increase the number of experiments.

Oh, and by the way, who says that all players want to win the car? XKCD has a different take on it.

Have a great weekend, everybody.

1
* Please Login or Register to Comment on or Follow discussions.
avatar image
Feb 10, 2017 at 03:06 PM edited Feb 10, 2017 at 03:07 PM
24
10 |10000 characters needed characters left characters exceeded