Hacker News new | ask | show | jobs
by epidemian 4220 days ago
Wow. As many others here, i was sure there wouldn't be a difference if Monty picked at random AND we ignored the cases where he picks the door with the car. But after reading "write the damn simulation!" too many times, i wrote one, being sure it would prove me right.

Of course, i was wrong :D

The simulation testing the four possible scenarios:

  #!/usr/bin/env ruby
  
  def run_games(monty_knows:, change_choice:)
    options = [:goat1, :goat2, :car]
    total_games = 0
    wins = 0
  
    100000.times do
      choice = options.sample
      monty_choice = (options - [choice, (:car if monty_knows)]).sample
  
      # Don't consider cases where Monty shows a car.
      next if monty_choice == :car
  
      if change_choice
        choice = (options - [monty_choice, choice]).first
      end
  
      total_games += 1
      wins += 1 if choice == :car
    end
  
    wins / total_games.to_f
  end
  
  puts 'Monty knows & keep choice: %.2f' %
         run_games(monty_knows: true, change_choice: false)
  puts 'Monty knows & change choice: %.2f' %
         run_games(monty_knows: true, change_choice: true)
  puts 'Monty ignores & keep choice: %.2f' %
         run_games(monty_knows: false, change_choice: false)
  puts 'Monty ignores & change choice: %.2f' %
         run_games(monty_knows: false, change_choice: true)
Sample output:

  Monty knows & keep choice: 0.33
  Monty knows & change choice: 0.67
  Monty ignores & keep choice: 0.50
  Monty ignores & change choice: 0.50
So, in the case of Monty picking at random, even if we ignore the cases where he picks the car, your chances of winning do not improve by changing your first choice or not.

After verifying that the simulation makes sense, i tried to figure out why it makes sense.

In an information theory kinda way, it makes sense that if Monty picks at random then he is not providing any new information: you are just being shown what was behind a random door you didn't choose and you can't choose now. But that explanation is not intuitive to my brain.

I found it more intuitive to actually draw a decision tree with the possibilities and their probabilities. The tree is actually very simple:

With the Always Change Door strategy:

               car (1/3) -> LOSE (Monty always reveals goat,
              /                   we change and we always lose)
  first choice
              \                            goat (1/2) -> WIN (we change to the
               \                          /                   car door)
                goat (2/3) -> Monty choice
                                          \
                                           car (1/2) -> IGNORE
The probability of winning is 1/3 (2/3 * 1/2).

With the Always Keep Door strategy:

               car (1/3) -> WIN (doesn't matter what Monty chooses)
              /
  first choice
              \                            goat (1/2) -> LOSE (we keep our
               \                          /                    goat-hiding door)
                goat (2/3) -> Monty choice
                                          \
                                           car (1/2) -> IGNORE 
Same tree, but with win and lose cases inverted. The probability of winning is also 1/3.

In conclusion, my intuition sucks. Thanks for showing me so!

2 comments

Kudos for having enough doubt that your intuition was correct to actually write the simulation!

Self-doubt is a quantity often found wanting among smart people, computer programmers, and especially among the intersection ;)

Nice write-up.