Skip to content

Instantly share code, notes, and snippets.

@tomo3141592653
Last active December 22, 2015 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomo3141592653/eecb7db9a109eafbc190 to your computer and use it in GitHub Desktop.
Save tomo3141592653/eecb7db9a109eafbc190 to your computer and use it in GitHub Desktop.
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