-1
$\begingroup$

I have come across this problem which was apparently very famous some years ago, in which a person is placed in front of 3 doors: one of them has a stack of gold behind it, and the other two have nothing. The question is whether the person should switch doors or not before opening one. Apparently, the answer is one should always switch doors.

In order to check this, I have written a small piece of code in which I run $10^6$ iterations. In each of them, I shuffle the doors, make a choice of door and then switch to another door (randomly). I add +1 point if I hit the stack of gold and $0$ if I don't. Finally, I count all the successful iterations and divide it by the total number of iterations. If the proposed result is correct, I should get $\frac{pts.}{N}>1/3$. Nonetheless, I see it converges to this value. What am I not getting? Here is my code:

import numpy as np pts = 0 doors = np.array([0,0,1]) N=1000000 for i in range(N): np.random.shuffle(doors) choice1 = np.random.randint(0, 3) # This is the first choice, I should switch choice2 = np.random.choice([num for num in range(0,3) if num != choice1]) pts += doors[choice2] print(pts/N) 

Note: I have checked that the "doors" array is indeed shuffling in every iteration, the numpy method "shuffle" just returns None, so you don't need to re-assign it to the original array, it just acts on the memory address.

$\endgroup$
4
  • 3
    $\begingroup$ You misheard the problem. YOUR problem is you pick one of three doors. Then with no more information you decide if you want to switch. Well, switching is no different than just picking another door in the first place. The actual puzzle is that after you pick your first door, a "host" will show you a door you didn't pick that has nothing behind it. You now have a choice: keep your door or switch to the third door (the door the host showed you is no longer an option). If you program with that change, you'll see the probability converges to $\frac 23$. $\endgroup$ Commented Sep 21 at 15:21
  • $\begingroup$ @fleablood I did and it worked, thank you very much!! $\endgroup$ Commented Sep 21 at 16:52
  • $\begingroup$ You were able to write a coherent program? That's good! Glad it helped. There are many explanations to why this work but the most comprehensive (but not intuitively convincing) is that the host will always show you an empty door so what the host is saying is "You can keep your door or you can switch to the other two doors. I'll just show you one of the other two doors that is empty". As you have a 1/3 chance on your first guess then switching to the other two is 2/3. That that host artificially opened one doesn't actually change anything. $\endgroup$ Commented Sep 22 at 3:18
  • $\begingroup$ Another is to switch it from 3 doors to many doors. "Guess my birthday" "Okay, May 2" "All right, my birthday might by May 2nd; But I'll tell you 363 days it isn't; It's not in Jan. Feb, March. April, May 1, May 3 to 31, June, July, Aug 1 to 24, nor Aug 26 to 31, not in Sept. Oct Nov. or December. So it is either May 2nd or Aug. 25. Are you going to stick with you first guess of May 2nd, or switch to to the other available choice: Aug 25th?" $\endgroup$ Commented Sep 22 at 3:28

1 Answer 1

0
$\begingroup$

You have misunderstood the Monty Hall Problem . Your code does not account for the fact that the game show host never shows you the gold when opening one of the two doors you did not choose. You decide whether or not to switch only after you get that new information.

$\endgroup$
3
  • $\begingroup$ Thanks for your answer! Would you mind explaining it a bit more? As I see it, I am simply showing the player whether the door they chose has the stack of gold behind it or not, right? $\endgroup$ Commented Sep 21 at 14:57
  • $\begingroup$ There are many explanations out there, so I won't add another here. Study the wikipedia page and the linked answer in the comment from @MartinR . $\endgroup$ Commented Sep 21 at 15:00
  • $\begingroup$ ", I am simply showing the player whether the door they chose has the stack of gold behind it or not, right?" No. The "host" shows the player a door that does not have a bag of gold. If the player chose the door with gold, the host will randomly show them another door; if the player chose a bag with no gold, the host will show them them other door with no gold. The host *always shows a) a door with no gold b) a door the player did not pick. $\endgroup$ Commented Sep 21 at 15:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.