sheesh, 150 posts about this same problem? well, anyways, here's a python implementation of the problem for anyone who still has doubt that switching is the way to go:
(if you can't program or don't know python, don't worry.. python is very readable code)
(grr, formatting code in these forums is HARD.. where is our 'pre' tag?)
from random import randint
# this function runs through the process one time, and returns TRUE
# if the contestant wins the car. if argument "switch" is TRUE it
# will switch the answer, and if FALSE it will stick with the first
# choice
def wincar(switch):
cardoor = randint(1,3)
firstpick = randint(1,3)
# get the door that the host reveals (goat)
freebie = 1
while (freebie != cardoor and freebie != firstpick):
freebie = freebie + 1
if (switch):
newpick = 1
while (newpick != freebie and newpick != firstpick):
newpick = newpick + 1
return (newpick == cardoor)
else:
return (firstpick == cardoor)
def getwins(attempts, switch):
wins = 0
for x in xrange(0, attempts):
if wincar(switch): wins = wins + 1
print "Won the car " + str(wins) + " times out of " + str(attempts) + " attempts\n"
def main():
print "Results when you stick with initial choice:"
getwins(1000,0)
print "Results when you always switch:"
getwins(1000,1)
main()
Here's the output when running the program:
C:\TEMP>python doors.py
Results when you stick with initial choice:
Won the car 312 times out of 1000 attempts
Results when you always switch:
Won the car 696 times out of 1000 attempts
Running it over and over again produces about the same result (1/3 and 2/3)