Created
May 8, 2021 16:03
-
-
Save telliott99/50d8ffcded903763ac4f20f515b7b481 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
from matplotlib import pyplot as plt | |
import sys, random | |
N = int(sys.argv[1]) | |
n = 100 | |
L = list() | |
for i in range(N): | |
count = 0 | |
prev = 0 | |
while True: | |
r = random.random() | |
if count == 0: | |
count += 1 | |
elif prev < r: | |
prev = r | |
count += 1 | |
else: | |
L.append(count) | |
break | |
print(sum(L)/len(L)) | |
''' | |
> p3 script.py 10000000 | |
2.718501 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment