Why the 'Sleeping Beauty Problem' Is Keeping Mathematicians Awake(scientificamerican.com) |
Why the 'Sleeping Beauty Problem' Is Keeping Mathematicians Awake(scientificamerican.com) |
Does this not simulate the problem in python?
import random
coin = ["heads", "tails"]
guess = "heads"
guesses_correct = 0
wakings = 0
n = 1_000_000
for _ in range(n):
actual = random.choice(coin)
if actual == guess:
wakings += 1
guesses_correct += 1
else:
wakings += 2
print(f"guessed correctly: {guesses_correct/wakings:0.2f}%")