import io
import numpy

l = 60
r = 10

N = 20

def throw():
    x = (numpy.random.rand() - 0.5) * l
    y = (numpy.random.rand() - 0.5) * l
    #print(x, y)
    outcome = 0
    if(x * x + y * y <= r * r):
        outcome = 1

    return outcome

def experiment():
    throws = 0
    hits = 0
    while hits < N:
        out = throw()
        hits += out
        throws += 1

    return throws

numTrials = 10000
T = 0
for i in range(0, numTrials):
    t = experiment()
    T += t

empiricalNumThrowsForN = (T * 1.0) / numTrials

print("Empirical estimate = " + str(empiricalNumThrowsForN))

analyticalAnswer = l * l * N / (numpy.pi * r * r)
print("Analytical answer = " + str(analyticalAnswer))
