# VBForums CodeBank > CodeBank - Visual Basic .NET >  [WPF/VB.Net] Monty Hall Puzzle demo

## Niya

I stumbled upon something rather interesting on YouTube yesterday called the Monty Hall Problem. Imagine you were given 3 doors from which you can choose one. Behind one of these doors is a prize but you do not know which door it's behind so you must guess. This means you have a 1 in 3 chance of choosing the correct one. Now lets say you are asked to choose a door and after making that choice, one of the doors which do not host the prize is revealed to you. This leaves you with the door you chose and another door. Now, you are offered the chance to either change your choice or stay with the choice you made, what would you do? 

This is where it got interesting. Everyone's first instinct, including mine was to believe the odds of picking the correct answer goes down from 1 in 3 to a 1 in 2 chance. Better odds than before but it feels like 50/50 whether or not you change your choice after the false door was revealed. It turns out that the best option is to actually change your choice. This puzzle fooled a lot of very intelligent and highly educated people. I'm not going to bore you with the details of all this and the technical details behind this puzzle. You can check out video yourself where it's all explained:-



Nonetheless, I found this puzzle rather intriguing and I didn't really understand it at first so I wrote a small WPF application to actually test whether always choosing a different door after a reveal of false doors really does improve the odds, which of course they absolutely did. The application even allows you to go beyond just 3 doors which will very quickly give you a solid intuition for why this puzzle works the way it does.

See the attachment for the application. You will need Visual Studio 2022 to open it.

Here is a small video of me demonstrating how to use the application.



Have fun.

----------


## wqweto

> . . . so I wrote a small WPF application to actually test whether always choosing a different door after a reveal of false doors really does improve the odds, which of course they absolutely did.


What you've done is called Monte Carlo simulation and is a viable algorithm from CS -- I've used this in programming competition in my high-school years :-))

I've recently re-watched 21 movie and solving the Monty Hall Problem was how the main character was picked up by his math teacher for the crew to hit the Vegas casinos.

My IQ is obvious not as high as Savant's (though not too bad either) so I couldn't figure out the odds without pen and a paper on first occasion with the problem. Some Nobel Prize winners failed too so I don't feel too bad about it at all. . . :-))

cheers,
</wqw>

----------


## OptionBase1

> *Everyone's first instinct*, including mine was to believe the odds of picking the correct answer goes down from 1 in 3 to a 1 in 2 chance.


Meh, I'm sure there are plenty of people who don't understand odds that wouldn't even be able to get that far.

A long time ago I had a discussion with a friend about this, who was convinced it was 1/2.  And what made it click for him was me saying, what if instead of opening a losing door, he simply said "Would you like to switch from your 1 selected to the other 2 doors".  Now it is clear that your odds of winning are 2/3 of the time.  And you know that one of them obviously is a losing door, so him revealing that losing door "ahead of your switch to the other 2 doors" doesn't change anything.

----------


## OptionBase1

Another way to examine it is to simply keep track of the odds.  We know, at any point in the game, the odds of winning + the odds of losing must equal 1.

When the initial selection is made, the odds of winning are 1/3.  We also know that of the two unselected doors, one of them is guaranteed to be a loser.  So, unless we are presented with new information, our odds of winning remain at 1/3.  The fact that a non-selected losing door is revealed to be a losing door isn't new information, so after it is opened our odds of winning with our initially selected door remain at 1/3.  So the odds of winning by switching must be 2/3, since the combined odds must equal 1, and "staying or switching" are the only two options.

----------


## passel

> Meh, I'm sure there are plenty of people who don't understand odds that wouldn't even be able to get that far.
> 
> A long time ago I had a discussion with a friend about this, who was convinced it was 1/2.  And what made it click for him was me saying, what if instead of opening a losing door, he simply said "Would you like to switch from your 1 selected to the other 2 doors".  Now it is clear that your odds of winning are 2/3 of the time.  And you know that one of them obviously is a losing door, so him revealing that losing door "ahead of your switch to the other 2 doors" doesn't change anything.


Yeah, I used the same example logic when the question came up among some friends at lunch in high school nearly fifty years ago. I also went to the one door in a hundred example when it still didn't make sense to someone, i.e. pick one door and then either keep the door you picked or switch to the other 99, which would you choose.

----------


## Niya

> What you've done is called Monte Carlo simulation and is a viable algorithm from CS -- I've used this in programming competition in my high-school years :-))


Wow. I had no idea that this existed in the realm of the study of probability. Now you have me thinking about all the computation problems I encountered in my life that I could not find a solution for using normal algebraic math. I find this very fascinating.




> Some Nobel Prize winners failed too so I don't feel too bad about it at all. . . :-))





> Meh, I'm sure there are plenty of people who don't understand odds that wouldn't even be able to get that far.
> 
> A long time ago I had a discussion with a friend about this, who was convinced it was 1/2.


What I found so fascinating about this problem is how easy it is for even smartest of us to jump to the wrong conclusion. It reveals so clearly how much of our default intuitions about probability is so wrong. It may even explain why gambling is popular enough to generate billions in revenue worldwide. It is no secret that casinos and other facilitators of gambling cultivate odds that favor them over their patrons, yet despite the wealth of information on this, you can find no shortage of people willing to throw away enormous amounts trying to "beat the house". I think we humans are just bad at probability.




> I also went to the one door in a hundred example when it still didn't make sense to someone, i.e. pick one door and then either keep the door you picked or switch to the other 99, which would you choose.


This is when it really clicked for me as well. That's why I designed the application such that you can put as many doors as you like, a hundred, a thousand. I think it's the best way to illustrate visually and mechanically why switching is the better choice.




> Another way to examine it is to simply keep track of the odds.  We know, at any point in the game, the odds of winning + the odds of losing must equal 1.
> 
> When the initial selection is made, the odds of winning are 1/3.  We also know that of the two unselected doors, one of them is guaranteed to be a loser.  So, unless we are presented with new information, our odds of winning remain at 1/3.  The fact that a non-selected losing door is revealed to be a losing door isn't new information, so after it is opened our odds of winning with our initially selected door remain at 1/3.  So the odds of winning by switching must be 2/3, since the combined odds must equal 1, and "staying or switching" are the only two options.


This is a nice way of looking it at. I never thought about it like this.




> And what made it click for him was me saying, what if instead of opening a losing door, he simply said "Would you like to switch from your 1 selected to the other 2 doors".  Now it is clear that your odds of winning are 2/3 of the time.  And you know that one of them obviously is a losing door, so him revealing that losing door "ahead of your switch to the other 2 doors" doesn't change anything.


Ah yes. This is clever too. A good way to explain it to the most stubborn of laymen. I don't think I can think of a better way to explain it to a layman than this.

----------

