Last active
April 12, 2021 21:35
-
-
Save LinqLover/bdb09f460522f8b5ef69d3a3b0f97c33 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 random | |
from tqdm import tqdm | |
def test_pi(x, y): | |
return int(x ** 2 + y ** 2 <= 1) * 4 | |
def test_it(n): | |
return np.mean([ | |
test_pi(random.uniform(0, 1), random.uniform(0, 1)) | |
for _ in tqdm(range(n)) | |
]) | |
if __name__ == '__main__': | |
print(test_it(10000000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment