
Show HN: Understanding the Monty Hall paradox through code - deeg
https://github.com/DeegC/monty_hall_paradox
======
drewm1980
If you phrase it adversarially it makes more sense... 2/3 of the time you
select a goat and force Monty to reveal the other goat. For those 2/3, you're
guaranteed to get a car by switching. The remaining third you get a goat.

If you take the "stay" strategy... 1/3 you hit the car and keep it. 2/3 you
hit a goat and keep it.

In summary... "switch" is 2/3 car, "stay" is 2/3 goat.

In these times you should choose "stay" and hope to get a goat so you can turn
grass into food. Cars are overrated.

------
andischo
The easiest explanation I've ever heard and which immediately made me
understand it was the following:

Instead of 3 doors, imagine there are 100. 99 of which have a goat and only
one of which has a price behind it. Now blindly choose a door and the host
opens 98 of the other doors which have a goat behind it. Would you switch your
door now, given the choice?

It's easy to see that your probability of choosing a "wrong" door when you had
100 doors to choose from was much higher than choosing the right door when you
only have two doors to choose from.

This method of thinking, i.e. increasing or decreasing the problem space by
some orders of magintude has helped me a lot in thinking about problems and
their solutions in general.

~~~
millstone
I'm the host, and I also happen to be blind. I chose 98 doors and none of them
have the car - terrible luck on my part! But probably this lends some credence
to your initial guess?

~~~
andischo
That is also a very interesting way to think about it, if I understood you
correctly. Seeing the host as another player, any "bad luck" he has, should
translate into myself having a higher chance of success if used correctly.

~~~
hanoz
With the host as another blind player, his opening of 98 goat doors only
increases the probability you were right from 0.01 to 0.5, so still makes no
difference for you to change. But of course the original version of the
problem is predicated on the host knowing where the car is and only revealing
goats.

------
aszs
One thing that intrigued me about this puzzle is wondering what mental model
for probability would make solving it intuitive? The one that works for me was
thinking about it in terms of information:

Because Monty can never choose the door you first picked he can't give you any
new information about that door. So when he reveals which of the remaining
doors has a goat, he is only giving us new information about those remaining
doors. That information reduces the odds on the remaining doors and that is
why you should always switch.

~~~
kortex
If you switch "you" get to "open" two doors in fact, not one. It's just that
Monty picks which one for you. And since your choice is random, you might as
well let an RNG do it for you.

If you consider it two independent rounds instead of stay/switch,

Stay: you get to roll 1d3, "1" wins

Switch: you get to roll 1d3, "1" loses, "2" or "3" wins

------
lordnacho
The main thing that seems to cause the paradox is a lack of specificity around
the door opening mechanism. If you make it clear that Monty only opens a door
that will definitely be empty, I find that most commentators will agree that
Marilyn is correct, you should switch.

~~~
niel
The original question that vos Savant responded to contains the phrase "...and
the host, who knows what's behind the doors, opens another door, say No. 3,
which has a goat..." \- I don't know how they could be any more specific.

If the host opens the door with the car, the game would be over anyway. It is
clearly implied that the host always opens a door with a goat.

~~~
tromp
> I don't know how they could be any more specific.

"the host opens another door that he knows has a goat behind it, say No. 3,"

Using the knowledge of where the car is to avoid showing it, is more specific
than just having the knowledge, and possibly still opening at random.

~~~
niel
Whether the host opens a door with a goat or a car determines whether the game
can still be played at all. How that door is selected does not factor into
whether the contestant should switch or not in any way.

I think the source of the paradox lies somewhere in the biases (the Endowment
effect or Status Quo bias) as discussed in the Wikipedia article about the
problem - not with how the question was stated and especially not with the
part about how the host selects a door.

~~~
CJefferson
Ah, you are wrong (and this is often confusing to people).

If you model this game where the host chooses randomly, and might open the car
door (when that hapoens the player instantly loses) , then there is no point
switching.

I think the fact this does matter is the source of many people's confusion.

~~~
Sandman
_then there is no point switching_

Why not? Your chances of choosing the correct door were 1 in 3 from the start.
That doesn't change with the fact that the host opens the doors at random.

~~~
deeg
Sorry for the late reply, but if you look at the original article on GitHub I
explore that scenario in the code. The answer is that if Monty randomly opens
a door then the contestant automatically loses 1/3 of the time before given a
chance to switch.

------
dpflan
Monty Hall himself wrote to the Harvard C.S. Professor Lawrence Denenberg
questioning the counter-intuitive logic:

> [https://stats.stackexchange.com/questions/373/the-monty-
> hall...](https://stats.stackexchange.com/questions/373/the-monty-hall-
> problem-where-does-our-intuition-fail-us/23674#23674)

____

The topic of the counter-intuitive nature of probability reminds of Newton's
letter to Pepys - "In 1693, Isaac Newton answered a query from Samuel Pepys
about a problem involving dice. Newton’s analysis is discussed and attention
is drawn to an error he made."

Here is the classic Newton-Pepys Problem
[http://www.datagenetics.com/blog/february12014/](http://www.datagenetics.com/blog/february12014/)

Here is the Newton-Pepys problem explained by Professor Joe Blitzstein in the
Harvard class Stats110:
[https://www.youtube.com/watch?v=P7NE4WF8j-Q&feature=youtu.be...](https://www.youtube.com/watch?v=P7NE4WF8j-Q&feature=youtu.be..).

Here is further discussion about the logical error Newton made in his
solution:
[http://arxiv.org/pdf/math/0701089.pdf](http://arxiv.org/pdf/math/0701089.pdf)

------
harimau777
It seems to me that a lot of what trips people up is that they don't realize
that the host specifically opens a door which they know does not to contain a
car (as opposed to selecting the door to open randomly).

Therefore, it seems to me that many people fall for it not so much because
they misunderstand the probability but because the rules of the game are
designed to be misleading.

------
paultopia
For a more prosaic use of code to help people understand, I once wrote a quick
simulation to help get it into the intuitions of my students: [https://paul-
gowder.com/montyhall/](https://paul-gowder.com/montyhall/)

------
anotheryou
I finally understood it!

I always wondered why it's not 50/50 if I enter the room late. How can a past
event that now seems irrelevant change the odds.

Basically you watch Monte jump around and see which doors he avoids because
they have prices. Now you can't make that observation about your own door
because he'd never touch it anyways and he jumps just once but sometimes
skipping a door if his random hits the price. The fact that it's just 3 doors
so just one is left makes it even more quirky, but doesn't change much.

So you know the other door is a door monty pontentialy avoided not to reveal
the price.You don't have that information about your door.

~~~
greypowerOz
edit oops i should have refreshed before duplicating this thought !!!!

funny how different people grasp things.. this code example didn't really
click with me, but someone else explained it by imagining 100 doors, not 3.
After you choose one door, 98 of the remaining 99 doors (all with goats behind
them..) are opened.... leaving 1.

stay or switch? :)

~~~
anotheryou
yea the code didn't click with me either, just "focus on what monte does"
helped me along. Your train of thought clearer, great :)

------
bmn__
Much more complete discussion of the problem, with strategy variants and code:
[http://loup-vaillant.fr/tutorials/monty-hall](http://loup-
vaillant.fr/tutorials/monty-hall)

Author is also a HNer: [https://news.ycombinator.com/user?id=loup-
vaillant](https://news.ycombinator.com/user?id=loup-vaillant)

------
gugagore
For this and other probability "paradoxes" explained through code, check out
this great notebook:
[https://nbviewer.jupyter.org/github/norvig/pytudes/blob/mast...](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/master/ipynb/ProbabilityParadox.ipynb)

~~~
Stratoscope
That is great, thanks!

This note in particular could be a lesson for many things in life:

> When I believe the answer is 1/3, and I hear someone say the answer is 1/2,
> my response is not _" You're wrong!"_, rather it is _" How interesting! You
> must have a different interpretation of the problem; I should try to
> discover what your interpretation is, and why your answer is correct for
> your interpretation."_ The first step is to be more precise in _my_ wording
> of the experiment...

------
oceanghost
Why do explanations of this problem never mention conditional probability, on
which the explanation is based?

There are dozens of videos explaining conditional probability on youtube, but
basically, the taking away of a door gives us additional information about the
state of the system. It is counter-intuitive, but it's not a mystery.

This principle is used everywhere to optimize real-world problems.

------
textread
There's a Kevin Spacey movie scene on this:
[https://www.youtube.com/watch?v=cXqDIFUB7YU](https://www.youtube.com/watch?v=cXqDIFUB7YU)

------
davidmurdoch
Michael Stevens of Vsauce does a fantastic job explaining why this works:
[https://youtu.be/TVq2ivVpZgQ](https://youtu.be/TVq2ivVpZgQ)

------
thecopy
for me it clicked when i realized he will only open the bad door which you
have not chosen. Even if you chose the bad door he will never open that one to
show you. He’ll always open the other

------
ngcc_hk
The simplest solution is you Always switch as it meant 2/3 instead of 1/3
winning chance. the door opening earlier or (clearer and easier to understand)
later is just to help you to check your 2/3 pool.

------
29athrowaway
Github supports the IPython notebook format.

I much rather prefer that for literate programming.

