Last active
December 22, 2015 09:38
-
-
Save tomo3141592653/eecb7db9a109eafbc190 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 random | |
import math | |
def gcd(a, b): | |
while b: | |
a, b = b, a % b | |
return a | |
count_coprime = 0 | |
count_all = 0 | |
while(1): | |
count_all += 1 | |
a = random.randint(1,100000000) | |
b = random.randint(1,100000000) | |
if(gcd(a,b) ==1 ): | |
count_coprime += 1 | |
prob = 1.0 * count_coprime / count_all | |
if prob >0 and count_all %10000 ==0: | |
pi = math.sqrt(1/(prob/6)) | |
print pi,count_all | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment