Skip to content

Commit 0a26492

Browse files
committed
Additional explanation on Monty Hall
1 parent d931335 commit 0a26492

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Monty Hall Problem/README.markdown

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ Since probabilities always need to add up to 100%, the chance that the prize is
6969

7070
This is hard to wrap your head around, but easily shown using a simulation that runs a significant number of times. Probability is weird.
7171

72+
By the way, you can simplify the code to this:
73+
74+
```swift
75+
let prizeDoor = random(3)
76+
let chooseDoor = random(3)
77+
if chooseDoor == prizeDoor {
78+
winOriginalChoice += 1
79+
} else {
80+
winChangedMind += 1
81+
}
82+
```
83+
84+
Now it's no longer a simulation but the logic is equivalent. You can clearly see that the `chooseDoor` only wins 1/3rd of the time -- because it's a random number between 1 and 3 -- so changing your mind must win the other 2/3rds of the time.
85+
7286
[Monty Hall Problem on Wikipedia](https://en.wikipedia.org/wiki/Monty_Hall_problem)
7387

7488
*Written for Swift Algorithm Club by Matthijs Hollemans*

0 commit comments

Comments
 (0)