Created
September 28, 2023 22:15
-
-
Save DiogoRibeiro7/4e929884ab6603274ebff46914f31f87 to your computer and use it in GitHub Desktop.
This file contains 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 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