Maths challenge No. 3

Page 7 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

Dexion

Golden Member
Apr 30, 2000
1,591
0
76


<< Dexion, if you open two doors the chance of me finding the bathroom is 100% >>



Yep, your right. However, what I wanted to say was finding the toilet behind the &quot;opened&quot; doors. Not behind a closed one. In that case, it would be 2/3 chance. Should I have made it more &quot;restricted&quot;? as to having a 2 keys for 3 locked doors? LOL You get my point.

I still don't understand why theres such a huge difference in the concept of switching? The word switching is rather decieving, infact your only taking another chance.

Just read Gustavus's explaination, if that doesn't make sense to you, drop the entire thing. Its getting frustrating for some of us trying to explain it. Like how Callspread said, just don't go betting on anything.
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
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 &quot;switch&quot; 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 &quot;Won the car &quot; + str(wins) + &quot; times out of &quot; + str(attempts) + &quot; attempts\n&quot;


def main():

        print &quot;Results when you stick with initial choice:&quot;
        getwins(1000,0)

        print &quot;Results when you always switch:&quot;
        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)
 

konichiwa

Lifer
Oct 9, 1999
15,077
2
0
Gustavus:

I don't speak a word of Japanese (well, other than konichiwa :p) but it means Good Afternoon. Or is it hello? Ah, I can never remember. :confused:
 

qacwac

Senior member
Oct 12, 2000
408
0
0
Thanks to everybody who clearly explained it was 1/3 and 2/3.

I stole your code hatboy to look at later. I don't know java but I know a little c++ so I wanted to compare. If that upsets you then I'll delete it but I didn't think you'd care.