Created
February 24, 2024 21:06
-
-
Save romanmichaelpaolucci/a0e54895fa7dad856009a0e887646f2a to your computer and use it in GitHub Desktop.
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 numpy as np | |
def HHH(p): | |
return 1/p + 1/(p**2) + 1/(p**3) | |
tosses = [] | |
for i in range(10000): | |
chain = [] | |
while True: | |
chain.append(np.random.choice([0, 1], p=[.5, .5])) | |
if len(chain) > 2: | |
if chain[-1] == 1 and chain[-2] == 1 and chain[-3] == 1: | |
tosses.append(len(chain)) | |
break | |
print(HHH(1/2)) | |
print(np.mean(tosses)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment