Naturally I would accept a computer program as evidence. Would be odd to say no. However we will have to agree on the algorithm and this whole thing gave me a terrible headache. I'll check macgyver's later.

over and out.

This is a discussion on *Something about probablility* within the **A Brief History of Cprogramming.com** forums, part of the Community Boards category; Naturally I would accept a computer program as evidence. Would be odd to say no. However we will have to ...

- 03-08-2008 #61
Naturally I would accept a computer program as evidence. Would be odd to say no. However we will have to agree on the algorithm and this whole thing gave me a terrible headache. I'll check macgyver's later.

over and out.Originally Posted by**brewbuck**:

*Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.*

- 03-08-2008 #62

- 03-08-2008 #63

- Join Date
- Oct 2001
- Posts
- 2,129

No matter what happens, the host will remove one of the donkeys. So then it's 50/50.

Does anybody care to try to disprove this?

- 03-08-2008 #64
Ok, my last attempt to explain it:

There is a 2/3 probablility of winning by switching from the outset. Your odds don't change once you select the first door. This is because, at the start there will allways be a 2/3 probability that one of the doors you do not chose to begin with will have the money in it.

First off these are all possibilities of what can be behind the doors:

Code:Host | You donkey donkey | money money donkey | donkey donkey money | donkey

Code:donkey, donkey money, donkey donkey, money

Code:donkey money money

Code:money donkey donkey

Code:Host | You donkey| money money | donkey money | donkey

Last edited by mike_g; 03-08-2008 at 05:24 PM.

- 03-08-2008 #65

- Join Date
- Jan 2005
- Posts
- 7,348

>> Does anybody care to try to disprove this?

I don't know about "proof", but unfortunately it is wrong.

As I mentioned earlier, the host's choice of what to open depends on your original choice of your door, so you cannot start over with a new probability just because a door has been removed.

If the host opened a door at random and it ended up being a donkey, then the chance would be 50-50. But the host doesn't open a door at random. The host opens the door based on your choice and his knowledge of what is behind the doors.

- 03-08-2008 #66

- Join Date
- Jan 2005
- Posts
- 7,348

You can also think about this alternative scenario. There are 50 doors. You pick 1. The host opens 48 doors that he knows all have donkeys. Should you switch?

- 03-08-2008 #67
Think I messed up my original program.

Try this one:

Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int doRound(void); int getRandomDoor(void); int doRound(void) { int iRightDoor, iGuess; iRightDoor = getRandomDoor(); iGuess = getRandomDoor(); return (iRightDoor!=iGuess); } int getRandomDoor(void) { return rand() % 3; } int main(int argc, char *argv[]) { int i, times = 100, iSwitch = 0, iStay = 0; srand(time(NULL)); if(argc > 1) { times = (int)strtol(argv[1], NULL, 10); } for(i=0;i<times;i++) { if(doRound()) { iSwitch++; } else iStay++; } printf("Switching was appropriate %d times\n", iSwitch); printf("Staying was appropriate %d times\n", iStay); return 0; }

Code:Switching was appropriate 69 times Staying was appropriate 31 times Switching was appropriate 70 times Staying was appropriate 30 times Switching was appropriate 65 times Staying was appropriate 35 times Switching was appropriate 65 times Staying was appropriate 35 times

- 03-08-2008 #68
I need to dissect this because I believe herein lies the crux of the problem.

> If the host opened a door at random and it ended up being a donkey, then the chance would be 50-50.

Take notice of this statement:*If it happened to be a donkey, the chance would be 50-50.*The host opens the door based on your choice and his knowledge of what is behind the doors.

>

So he knows what door he can open to show the contestant a donkey. He does this all the time, no matter my choice. He can always open a door to a donkey.

So, what you think will be the odds?... 50:50, because that's exactly what the host does:*If it happened to be a donkey, the chance would be 50-50.*Originally Posted by**brewbuck**:

*Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.*

- 03-08-2008 #69
Here's another simulation that runs when your browser loads. It also has an informal explanation of why 2/3 for a switch is correct.

http://edp.org/monty.htm

- 03-08-2008 #70

- 03-08-2008 #71

- Join Date
- Oct 2001
- Posts
- 2,129

dammit.

- 03-08-2008 #72
Perhaps you would like to read:

Ask Dr. Math: FAQ: The Monty Hall Problem

Wolfram MathWorld: Monty Hall Problem

For a walkthrough simulation:

Let's Make a DealOriginally Posted by**Bjarne Stroustrup (2000-10-14)**

- 03-08-2008 #73

- Join Date
- Oct 2001
- Posts
- 2,129

If the donkeys and the money were placed behind the doors after the host made his/her choice, I would have been right.

- 03-08-2008 #74

- Join Date
- Jan 2005
- Posts
- 7,348

>> because that's exactly what the host does: If it happened to be a donkey, the chance would be 50-50.

There's a difference. If the host chooses a door at random, then there is a 1/3 chance he opens the door with the money. But if the host chooses a door on purpose, then that 1/3 chance disappears.

Let's say this happens 30 times. We'll label the doors as such:

Door A: money

Door B: donkey

Door C: donkey

So out of 30 times, 10 times the contestant chooses Door A, 10 times the contestant chooses Door B and 10 times the contestant chooses Door C.

Contestant chooses Door A, host opens Door B five times and Door C five times, all ten times a switch is bad.

Contestant chooses Door B, host opens Door C all ten times (because he can't open door A), switch is good all ten times.

Contestant chooses Door C, host opens Door B all ten times (because he can't open door A), switch is good all ten times.

So the switch is good 20 out of 30 times.

Let's do the same thing when the host doesn't know where the money is.

Contestant chooses Door A, host opens Door B five times and Door C five times, all ten times a switch is bad.

Contestant chooses Door B, host opens Door A five times and Door C five times, switch is good five times, and five times we ignore (because the original problem assumes the host opened a door with a donkey).

Contestant chooses Door C, host opens Door A five times and Door B five times, switch is good five times, and five times we ignore (because the original problem assumes the host opened a door with a donkey).

That's 10 times switch is bad, 10 times switch is good, and 10 times that are ignored because the problem assumes the host opens a door with a donkey.

See the difference?Last edited by Daved; 03-08-2008 at 07:16 PM.

- 03-08-2008 #75
Yup. I can see it now. It's an amazing paradox. Very invigorating. Also took a look at the links and on wikipedia.

It's a pleasure to see how wrong I am. This one is definitely going to my notebook.

Thanks a lot for the patience through the ordeal of trying to make see the lightOriginally Posted by**brewbuck**:

*Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.*

- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- Creating a game, from start to finish

- How to create a shared library on Linux with GCC - December 30, 2011
- Enum classes and nullptr in C++11 - November 27, 2011
- Learn about The Hash Table - November 20, 2011
- Rvalue References and Move Semantics in C++11 - November 13, 2011
- C and C++ for Java Programmers - November 5, 2011
- A Gentle Introduction to C++ IO Streams - October 10, 2011