Forgot your password?
typodupeerror

Comment Re:So I didn't randomly simulate it (Score 1) 566

Here is my very dodgey Python implementation to simulate the problem.  It it clearly in your favour to switch doors.

% cat monty.py
import random

class Game:
    def __init__(self):
        self.doors = ['car', 'goat', 'goat']
        random.shuffle(self.doors)

    def first_choice(self):
        self.choice = random.randint(0, 2)

    def monty_choice(self):
        door_nums = [0, 1, 2]
        door_nums.remove(self.choice)
        choice = random.choice(door_nums)
        if self.doors[choice] == 'goat':
            self.monty_choice = choice
        else:
            door_nums.remove(choice)
            self.monty_choice = door_nums[0]

    def switch(self):
        door_nums = [0, 1, 2]
        door_nums.remove(self.choice)
        door_nums.remove(self.monty_choice)
        self.choice = door_nums[0]

    def is_winner(self):
        return self.doors[self.choice] == 'car'

wins = 0
for i in range(1000):
    g = Game()
    g.first_choice()
    g.monty_choice()
    if g.is_winner():
        wins += 1

print 'Do not switch won %d times = %.0f%%' % (wins, wins * 100.0 / 1000)

wins = 0
for i in range(1000):
    g = Game()
    g.first_choice()
    g.monty_choice()
    g.switch()
    if g.is_winner():
        wins += 1

print 'Switch won %d times = %.0f%%' % (wins, wins * 100.0 / 1000)

Slashdot Top Deals

"Thank heaven for startups; without them we'd never have any advances." -- Seymour Cray

Working...