Last active
March 27, 2016 14:39
-
-
Save ties/b31dfd45116583542f88 to your computer and use it in GitHub Desktop.
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
| """ | |
| http://fivethirtyeight.com/features/should-you-pay-250-to-play-this-casino-game/ | |
| Suppose a casino invents a new game that you must pay $250 to play. The game | |
| works like this: | |
| The casino draws random numbers between 0 and 1, from a uniform distribution. It | |
| adds them together until their sum is greater than 1, at which time it stops | |
| drawing new numbers. You get a payout of $100 each time a new number is drawn. | |
| """ | |
| import random | |
| import collections | |
| ITER = 100000 | |
| COST = 250 | |
| gain = collections.Counter() | |
| for x in range(ITER): | |
| remain = 1 | |
| g = 0 | |
| while(remain > 0): | |
| remain -= random.random() | |
| g += 100 | |
| gain[g - COST] += 1 | |
| # Utility | |
| utility = sum(k*v for (k, v) in gain.items())/ITER | |
| print(utility) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment