Mainly Tech projects on Python and Electronic Design Automation.

Tuesday, October 03, 2017

Anti Monty Hall Problem

The Anti Monty Hall problem

As explained to Matt Parker by Rob Eastaway

The Game

There are five, identical, overturned, buckets. One conceals a treat from you, so that from your vantage point, all buckets look the same.

You are asked to choose three of the buckets.
Rob, (who plays the character of Monty Hall), then arranges your three to the left, and the other two to the right like so:

"Monty Hall", who always knows where the prize is, then proceeds to up-turn two of your buckets, and one of the others, that he knows does not conceal the prize, leaving just one of your choices, and one of the others to conceal the prize.

Monty Hall should then give you the choice of whether to stick with the one remaining down-turned bucket of your original choice, or switch to the other bucket.
  • In general, should you switch?

The Video

From the excellent numberphile channel.

The Python simulation

We need to work out, on average, whether to stick with the original choice or switch. So we need to to simulate over many trials.
In [18]:
from random import randrange, sample, shuffle

def anti_monty_hall(switch):
    # Upturn the buckets
    bucket = [False] * 5
    # Secretly hide the treat
    bucket[randrange(5)] = True
    # Choose three buckets, by index
    yours = sample(range(5), 3)
    others = list(set(range(5)) - set(yours))
    # Keep any index if it is to the treat, otherwise the random first
    your_indx = [indx for indx in yours if bucket[indx]] or yours[:1]
    other_indx = [indx for indx in others if bucket[indx]] or others[:1]
    your_bucket, other_bucket = [bucket[i[0]] for i in (your_indx, other_indx)]
    # Your answer to Monty hall
    return other_bucket if switch else your_bucket
In [21]:
In [25]:
iterations = 100000
print(f"Anti Monty Hall problem simulation for {iterations} iterations in each case:")
print(f"  Not switching allows you to win {sum(anti_monty_hall(switch=False) for _ in range(iterations))} times out of {iterations}")
print(f"  Switching allows you to win {sum(anti_monty_hall(switch=True) for _ in range(iterations))} times out of {iterations}")
Anti Monty Hall problem simulation for 100000 iterations in each case:
  Not switching allows you to win 60426 times out of 100000
  Switching allows you to win 39910 times out of 100000


The Simulation clearly shows that it is better to keep to your initial choice.
The Video explains that the odds are 60:40 which is neary the figure arrived at by the simulation.

No comments:

Post a Comment


Subscribe Now: google

Add to Google Reader or Homepage

Go deh too!

Blog Archive