Created
January 9, 2014 23:49
-
-
Save chris-taylor/8344336 to your computer and use it in GitHub Desktop.
You roll a dice up to three times. After each of the first two rolls you can choose to accept the number showing on the dice in dollars, or roll again. What is your expected winnings if you play optimally?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Probability | |
expected p = expectation (runProb p) | |
die = uniform [1..6] :: Bayes Double Integer | |
game n | |
| n == 0 = die | |
| otherwise = do | |
x <- die | |
if fromInteger x > expected next | |
then return x | |
else next | |
where | |
next = game (n-1) | |
{-------------------- | |
>> printProb $ game 2 | |
1 5.56% | |
2 5.56% | |
3 5.56% | |
4 16.67% | |
5 33.33% | |
6 33.33% | |
>> expected $ game 2 | |
4.66666666666667 | |
---------------------} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment