The Monty Hall problem is a ** problem of probability that is not intuitively convincing **. I didn't feel refreshed when I looked it up on the internet, so I decided to verify it myself.
You can get an overview on this site, but I will explain a little on this page as well.
When you select a box, it will open one of the outliers. After that, when you can change the selected box, the question is what is the best way to change or not change the options.
Box 1 | Box 2 | Box 3 |
---|---|---|
Hit | Off | Off |
For example, suppose the game organizer opens the out-of-box with Box 2 selected from the three boxes above (not yet opened). The situation is like below
Box 1 | Box 2 | Box 3 |
---|---|---|
Hit | Off | Off |
choosing | OPEN |
If the selection can be changed when Box 3 is found to be out of order, should it be changed? Is the problem.
Intuitively, there are two choices, hit or miss
, so it seems that it doesn't matter which one you choose, but mathematically it is as follows.
As it is | Change choices | |
---|---|---|
Probability of winning | 33% | 67% |
When I first saw this, I thought, "That's stupid ...". I wasn't quite convinced by looking at the explanation, so when I verified it using programming, I was very disappointed, so I will explain it. (But after all, new mysteries have increased)
We will verify using Ruby. (Although it can be refactored a little more, there are some parts that are redundantly written so that it is easy to understand what you are doing. Still, it may be a little difficult to understand ... lol)
ruby
#Number of trials (about 1 million times is enough)
number = 1_000_000
#Prepare hits and misses
win = 1
lose = 0
#Prepare a box
boxes = [win, lose, lose]
#Case 1 (when the options are not changed)
count = 0
number.times do
#Randomly decide which box to choose
random_number = [0, 1, 2].sample
selected_box = boxes[random_number]
#Open the out-of-box (this process doesn't make any sense because you won't change the options next)
random_number != 2 ? boxes.delete_at(2) : boxes.delete_at(1)
#Judge whether it is a hit with the selected box
count += 1 if selected_box == win
end
#Probability calculation
prob_1 = (count.to_f / number.to_f).round(5) * 100
puts "Probability of not changing options: #{prob_1}%"
#Case 2 (when changing options)
count = 0
number.times do
#Select a box
random_number = [0, 1, 2].sample
selected_box = boxes[random_number]
#Open the outlying box and change the selected box
if random_number == 0
boxes.delete_at(2)
selected_box = boxes[1]
elsif random_number == 1
boxes.delete_at(2)
selected_box = boxes[0]
else
boxes.delete_at(1)
selected_box = boxes[0]
end
#Judgment
count += 1 if selected_box == win
end
#Probability calculation
prob_2 = (count.to_f / number.to_f).round(5) * 100
puts "Probability of changing choices: #{prob_2}%"
The result of executing the file. You can see that your intuition is definitely wrong
I will try to solve this problem with Ruby and explain what I thought it was. The point is ** case classification according to the first choice **
When you select a box, it will tell you one box that is out of alignment, so this problem can be divided into the following two patterns.
Each probability is naturally as follows
Probability of choosing the winning box first | Probability of choosing the wrong box first |
---|---|
33% | 67% |
Next, let's look at the story of changing or not changing options from here.
If you don't change your options, you have to choose the winning box first. Originally, the probability of winning is 33%, so the probability of winning in this case is 33%.
When changing the options, if you first select the winning box, you will lose, and if you select the wrong box, you will win. In other words, in order to finally win, you must first select the out-of-box. At first, the probability of choosing a gap is 67%, so in this case the probability of winning is 67%.
I've explained so far, but some questions came up while I was writing. Let's say another participant arrives when the box is opened.
`At this time, from the perspective of another participant, which box is the winner? ``
It's okay to come up with this question, but I can't explain it well, so if you are familiar with mathematics, please comment.
It ended up being a little moody, but it was an interesting problem! The Monty Hall problem is simple but deep.
Recommended Posts