Skip to content

Instantly share code, notes, and snippets.

@DiogoRibeiro7
Created September 28, 2023 22:15
Show Gist options
  • Save DiogoRibeiro7/4e929884ab6603274ebff46914f31f87 to your computer and use it in GitHub Desktop.
Save DiogoRibeiro7/4e929884ab6603274ebff46914f31f87 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
def simulate_game():
tosses = 0
while np.random.choice(['H', 'T']) == 'T':
tosses += 1
return 2**(tosses + 1)
# Simulate the game 10,000 times to approximate the expected payoff
simulations = [simulate_game() for _ in range(10000)]
expected_payoff = np.mean(simulations)
print(f'Approximate Expected Payoff: {expected_payoff}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment