Sunday, July 20

Monty Hall Problem


The Monty Hall Problem is a puzzle named for Mr. Monty Hall, a game show host from the 60's and 70's.  The problem can be summed up as follows:
Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?
In the video above there is detail on how to intuitively find the answer where you should always switch.  Most people's intuitive answer is that after Monty Hall shows you the second door, you have a 50% chance of finding the sports car.  While this is true (given two doors, one car), this way of looking at the problem ignores the fact that Monty Hall just revealed a goat to us.  Remember that you had a 2/3 chance of getting a goat on your first pick.  The following table I believe demonstrates the choices well:
Car in Door 1
Car in Door 2
Car in Door 3
Result in picking door #1 and not switching
Result if switching

The program test

Although I was fully convinced that the switch was the right move, I decided to write a little python program to test the scenario in bulk.  This problem is better seen that your odds are better with always switching when you play the game more than once or twice (and not up to "dumb luck").


Given enough iterations, the success rate of switching should tend to 66% given 3 doors.  
Pseudo code
define Monty Hall Simulation(runs = 10000, random_seed = None):
    """Runs a simulation of a series of monty hall games. 'runs=' is the variable to
    determine the number of times you run the test.  The program will run 3 cases, always
    switch ("theoretical" optimal solution),  Never switching(sub-optimal solution), and
    Sometimes switching (ignoring the first bit of information in the monty hall problem).
    game = Game Show class
    always_switch, never_switch, sometimes_switch = [0, 0]  # a list form that keeps track of wins and losses
    for i in range(runs):
# always switch --------------------------------------------------------------------------
        j = = 0)
        if j is True:
            always_switch[0] += 1
            always_switch[1] += 1
# never switch ---------------------------------------------------------------------------
        k = = 1)
        if k is True:
            never_switch[0] += 1
            never_switch[1] += 1
# sometimes switch -----------------------------------------------------------------------
        l = = 2)
        if l is True:
            sometimes_switch[0] += 1
            sometimes_switch[1] += 1
# Print Results --------------------------------------------------------------------------
The Monty Hall class
class GameShow:
    define Initialization(self):
        """Initializes GameShow to a new instance"""
        doors = [0, 0, 0]
        first_choice = None
        second_choice = None
        reveal = None

    define play(self, strategy=0):
        """Strategy is how one plays the game
        0 is always switch to the other door
        1 is never switch (first choice is second choice)
        2 is sometimes switch (random choice on second choice)
        Any other value will give the 0 strategy"""
        if strategy is 0:
        else if strategy is 1:
        else if strategy is 2:
            s = random.choice([True, False])
        return self.is_win()

    define set_up(self, car=None):
        """resets the game"""

    define first_pick(self, pick=None):
        """picks a first pick"""
        self._first_choice= random.randint(0, 2)

    define reveal(self):
        """Game show host reveals a goat"""

    define second_pick(self, switch=True):
        """user picks a new door"""
        if switch is True:
            second_choice = 3 - (first_choice + reveal)
            second_choice = first_choice

    define is_win(self):
        """returns the win state"""


The following table was the output of the python script.  as can be seen below, the percentage to 3 significant figures pans out to 66% victory rate for always switching, 33% for sticking to your guns, and an even 50-50 for randomly switching.

Runs:  10000
Time:  0.72 seconds
Seed:  1
Always Switch:
Win:    6673
Loss:   3327
Percentage:  66 %
Never Switch:
Win:    3343
Loss:   6657
Percentage:  33 %
Sometimes Switch:
Win:    5041
Loss:   4959
Percentage:  50 %


Wednesday, January 29

Freshman English Journal

Back in high school, we had a an assignment during my freshman English class where we would have to write.  Just write something down 3 days a week for the entire semester.  Clueless as to what that meant, after my first semester I had my Journal checked.  It was a C+ if I recall correctly.  Either way, I passed, but I wasn't that good.  So for the next semester I decided to try to get more words on the paper.  One student claimed he wrote the same sentence over and over for his entire journal.  I thought I should at least get more creative.  I instead decided to copy the bible, word for word from Genesis 1:1 to whenever my assignment was completed (the 30 entries or so).  As it turns out I still didn't get an A, but the B I got was good enough for me.  Plus for a week I was able to recite Genesis, so I had that going for me.

Saturday, January 25


I am not entirely sure why I have irrational fear of some things.  I have no fear working on 400 tonne trucks, standing I front of objects that move 100+ mph, public speaking, and studying in a different language.  However, some things may be more difficult than other things to take care of in life.  I still haven't figured out how to overcome the fear of doing these other things, but everyone else is telling me to "just do it".  I suppose I will in fact just do it.  Wish me luck, I'm going in.

Wednesday, January 22

Rebooting the Blog

I have severely neglected my goal of publishing daily.  I figured I will drop this back down to weekly to see what will happen.
Since I have posted last, I have begun a Masters Thesis in Operations Research.  I hope to keep another separate blog up to date with relevant issues and research completed in my studies at UdeM.  Ah yes, I have also begun studying in la langue fran├žaise.  I have refereed to this departure form English as an adventure.  Even two weeks into my program here my french has improved dramatically.  I really do hope that my french will be almost fluent in the next two years.
I also hope to not be doing this every few months.  Another friend of mine is trying to post regularly.  I hope that as I see her post, I will keep posting as well.

Wednesday, December 4

Feast Day of Saint Barbra

Fun fact of the day: today is the feast day of Saint Barbra. She is the patron saint of Miners. in addition, she is the patron saint of artillerymen, people in ordnance disposal units, pyrotechnic technicians, and basically anyone else who's occupation has things go boom (or prevents them). It's kind of sad however if you look deeper into why she is the patron saint of explosives.  Her father chopped her head off for being a Christian, and then daddy was exploded in a burst of lightning from the sky.  Hell hath no fury like a woman's scorn with God on her side.

Happy Saint Barbra day!