Created
October 14, 2020 10:56
-
-
Save reiinakano/d255d1f8d5eadfb03ad64d4524bd856e to your computer and use it in GitHub Desktop.
st petersburg paradox
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 random | |
| import numpy as np | |
| def game(): | |
| total = 1 | |
| while True: | |
| if random.random() < 0.5: | |
| total += 1 | |
| else: | |
| break | |
| return 2 ** total | |
| def play_n_games(n): | |
| total = 0 | |
| max_val = 0 | |
| for i in range(n): | |
| val = game() | |
| total += val | |
| max_val = max(max_val, val) | |
| print(f'{i+1} games has a mean of {total/(i+1)} and max {max_val}') | |
| if __name__ == '__main__': | |
| play_n_games() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment