Skip to content

Instantly share code, notes, and snippets.

@reiinakano
Created October 14, 2020 10:56
Show Gist options
  • Select an option

  • Save reiinakano/d255d1f8d5eadfb03ad64d4524bd856e to your computer and use it in GitHub Desktop.

Select an option

Save reiinakano/d255d1f8d5eadfb03ad64d4524bd856e to your computer and use it in GitHub Desktop.
st petersburg paradox
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