Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kyleweiner/Jelly-Bean-Problem
A playground for modeling "The Jelly Bean Problem" presented by Tim Urban on Wait But Why.
https://github.com/kyleweiner/Jelly-Bean-Problem
Last synced: 25 days ago
JSON representation
A playground for modeling "The Jelly Bean Problem" presented by Tim Urban on Wait But Why.
- Host: GitHub
- URL: https://github.com/kyleweiner/Jelly-Bean-Problem
- Owner: kyleweiner
- Created: 2016-03-08T11:56:18.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-10T08:03:02.000Z (almost 9 years ago)
- Last Synced: 2024-04-22T12:31:42.608Z (8 months ago)
- Language: Swift
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- Awesome-Swift-Playgrounds - The Jelly Bean Problem - The Jelly Bean problem from Wait But Why. ⏳ (Theoretical Computer Science / Algorithms and Data Structures)
README
# Jelly Bean Problem
"[The Jelly Bean Problem](http://waitbutwhy.com/2016/03/the-jellybean-problem.html)" was published by Tim Urban of [Wait But Why](http://waitbutwhy.com) on March 7, 2016. The problem is mathematically equivalent to the famous [Monty Hall problem](https://en.wikipedia.org/wiki/Monty_Hall_problem) popularized by Marilyn vos Savant in 1990.
## Summary
You're presented with three jelly beans–one is harmless and two have a lethal poison. You don't know which jelly bean is safe, but you're required to eat one.
Upon making your choice, one of the two remaining jelly beans is removed–you're told it was lethal. Before consuming the jelly bean you initially selected, you're given the option to eat the remaining one instead.
Which jelly bean do you eat? Does it even matter?
## Conditions
This problem operates under the following conditions:
1. Only one jelly bean is safe to consume.
2. Two jelly beans will remain after the removal process; this includes the initially selected jelly bean.
3. The removed jelly beans are always lethal.
4. The option to switch the initially selected jelly bean for the remaining one is always provided.## Playground
The playground proves that your choice does matter–it's better to switch. There was initially a ⅓ probability of making a non-lethal selection. After the removal process, this probability remained the same. However, the probability of making a non-lethal selection by switching is now ⅔.
In the `scenario` below, the remaining choice is always taken (e.g. the remaining jelly bean is consumed–not the one that was initially selected). The `numberOfChoices` represents the number of jelly beans that were initially offered and the `playCount` is the number of times the `scenario` will run.
``` Swift
var scenario = Scenario(numberOfChoices: 3, playCount: 1000)!
scenario.run()
````The results are printed in the playground's sidebar. For the above `scenario`, it will be similar to the following:
> 😀 Survived by switching 667 times (66.7%).
>💀 Died by switching 333 times (33.3%).