from __future__ import division
from scipy import *

N = 7 # The grid size
d = 0.25 # The diameter of the coin
total_experiments = 100000

experiment_count = 0
success_count = 0
for i in xrange(total_experiments):
    # Draw uniform random location
    x = random.uniform(0, N)
    y = random.uniform(0, N)
    # Test the condition for success
    if (x-d/2 > int(x)) and (x+d/2 < int(x)+1) and\
            (y-d/2 > int(y)) and (y+d/2 < int(y)+1):
        success_count += 1
    experiment_count += 1

print "Theoretical result:", (1-d)**2
print "Empirical result: ", success_count / experiment_count

