## Let’s Make A Deal!

### July 24, 2009

Since the host always reveals a goat, the only thing that matters is whether the contestant’s initial pick was an auto or a goat; if the initial pick was an auto, staying wins, and if the initial pick was a goat, switching wins. The monty function (named after the original host, Monty Hall), plays *n* games and reports the number of wins when switching and the number of wins when staying:

`(define (monty n)`

(let monty ((n n) (switch 0) (stay 0))

(let ((auto (randint 3)) (pick (randint 3)))

(cond ((zero? n) (values switch stay))

((= auto pick) (monty (- n 1) switch (+ stay 1)))

(else (monty (- n 1) (+ switch 1) stay))))))

The variables `switch`

and `stay`

count the number of wins for each strategy. `(randint `

*n*`)`

returns a non-negative integer less than *n*; variable `auto`

records the location of the automobile, and variable `pick`

records the location of the contestant’s initial pick.

Running `monty`

for 100,000 contests shows a clear winner:

`> (monty 100000)`

66824

33176

You can run the program at http://programmingpraxis.codepad.org/54PDMDSv, including `rand`

and `randint`

, which are taken from the Standard Prelude.

When the contestant first makes a choice, he wins the automobile one-third of the time. The other two doors hide the automobile the other two-thirds of the time. When the host reveals a goat, the probabilities don’t change: the door first chosen by the contestant wins the automobile one-third of the time, and wins a goat two-thirds of the time. But since the other two doors hid the automobile two-thirds of the time, and we now know that one of the doors certainly does not hide the automobile, the other door must hide the automobile two-thirds of the time. It is better to switch than stay.

When this puzzle appeared in Marilyn vos Savant’s column in *Parade Magazine* in 1990, it generated more mail than any previous column; over a thousand people with Ph.D.s thought she was wrong.

I already knew that the correct answer is the probability of winning by switching is 2/3, but:

=> 0.66756

Ugly, but it works.

My Haskell version: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=7478#a7478

Lots of fun – thanks!

-Andy

I suggest also reading a nice treatment of this exact problem in “The man who loved only numbers” by Paul Hoffman.

I’m just now learning Python and figured I’d play around with its list capabilities for this one…

Originally I was using list comprehension to generate a list of random numbers (to indicate which door the car is behind) and keeping the contestant’s choice constant (always picking door number 1), but I realized it might be slightly faster to randomize the contestant’s choice and assume the car is always located behind door number 1 – simply using the list as a looping mechanism.

[…] Let’s Make A Deal! « Programming Praxis. […]

I made an attempt in PL/SQL (Oracle). I made the number of doors configurable (assuming that the host opens all doors except yours or the prize, or a random single door if you have chosen the prize door initially).

This produces the output

Which produces the following output

Yes, but when the game was played, did the host always open a door? Or did the host, for example, have the discretion to let the original choice go through. Unless we know this, it is meaningless to claim that we know the best strategy for the player.