In [1]:
%pylab inline

Populating the interactive namespace from numpy and matplotlib

In [2]:
import math
import random
import numpy as np
import matplotlib.pyplot as plt
from __future__ import  division

In [3]:
random.seed(27)

In [4]:
COLORS = ['red','black','yellow','green', 'purple']
NEEDLE_LENGTH = 1.0

def needle_orientation():
'''
Generate random center coordinates and angle of
orientation for a random needle
'''

x_center, y_center = random.uniform(0,3), random.uniform(0,3)
angle = random.random()*2*math.pi

return x_center, y_center, angle

def needle_construct_graph(L = NEEDLE_LENGTH, **mode):
'''
Given center coordinates and angle of orientation of needle construct
needle end point coordinates by making projections on both axes
and plot random needle of length 1 on grid
'''

xc, yc, theta = needle_orientation()
x_origin = (xc - L/2)*math.cos(theta)
y_origin = (yc - L/2)*math.sin(theta)

x_end = (xc + L/2)*math.cos(theta)
y_end = (yc + L/2)*math.sin(theta)

for name, value in mode.items():
if value is 'plot':
plt.plot((x_origin, x_end), (y_origin, y_end), random.choice(COLORS))
elif value is 'no_plot':
pass

return x_origin, x_end

def plot_grid_lines(i):
'''
Plot vertical grid lines with a length of 1 between lines
'''

plt.axvline(x=i, ymin=0, ymax = 5, linewidth=2, color='blue')

def needle_length(x1, y1, x2, y2):
'''
Check length of random is indeed 1
'''

return (math.pow(abs(y2-y1), 2) + math.pow(abs(x2-x1), 2))**0.5

def collision_detection(x_origin, x_end, lines):
'''
Detect when a random needle crosses a grid line
'''

count = 0
for line in lines:
if (x_origin <= line and x_end >= line) or (x_origin >= line and x_end <= line):
count += 1
else:
count += 0

return count

def calculate_pi(hits, pins, needle_length = NEEDLE_LENGTH):
'''
Calculate the value of pi
'''

return 2 * needle_length * (pins/hits)

In [5]:
pi_list = []

# trials = [10, 100, 1000, 10000, 50000, 100000]  # different number of trials
# trials = list(int(np.linspace(10,100000, 1000)))  # different number of trials
trials = [int(i) for i in list(np.linspace(10,100000, 1000))]
vlines = range(-4,4)

for pins in trials:
hits = 0
for pin in xrange(pins):
origin, end = needle_construct_graph(mode = 'no_plot')
hits += collision_detection(origin, end, vlines)
pi_list.append(calculate_pi(hits, pins))
print 'hits : %d, trials: %d, estimate pi = %1.4F' %(hits, pins, calculate_pi(hits, pins))


hits : 7, trials: 10, estimate pi = 2.8571
hits : 73, trials: 110, estimate pi = 3.0137
hits : 136, trials: 210, estimate pi = 3.0882
hits : 199, trials: 310, estimate pi = 3.1156
hits : 281, trials: 410, estimate pi = 2.9181
hits : 344, trials: 510, estimate pi = 2.9651
hits : 385, trials: 610, estimate pi = 3.1688
hits : 441, trials: 710, estimate pi = 3.2200
hits : 515, trials: 810, estimate pi = 3.1456
hits : 583, trials: 910, estimate pi = 3.1218
hits : 664, trials: 1010, estimate pi = 3.0422
hits : 704, trials: 1110, estimate pi = 3.1534
hits : 793, trials: 1211, estimate pi = 3.0542
hits : 845, trials: 1311, estimate pi = 3.1030
hits : 912, trials: 1411, estimate pi = 3.0943
hits : 962, trials: 1511, estimate pi = 3.1414
hits : 1036, trials: 1611, estimate pi = 3.1100
hits : 1121, trials: 1711, estimate pi = 3.0526
hits : 1150, trials: 1811, estimate pi = 3.1496
hits : 1229, trials: 1911, estimate pi = 3.1098
hits : 1254, trials: 2011, estimate pi = 3.2073
hits : 1382, trials: 2111, estimate pi = 3.0550
hits : 1442, trials: 2211, estimate pi = 3.0666
hits : 1482, trials: 2312, estimate pi = 3.1201
hits : 1574, trials: 2412, estimate pi = 3.0648
hits : 1618, trials: 2512, estimate pi = 3.1051
hits : 1657, trials: 2612, estimate pi = 3.1527
hits : 1755, trials: 2712, estimate pi = 3.0906
hits : 1812, trials: 2812, estimate pi = 3.1038
hits : 1870, trials: 2912, estimate pi = 3.1144
hits : 1926, trials: 3012, estimate pi = 3.1277
hits : 1987, trials: 3112, estimate pi = 3.1324
hits : 2048, trials: 3212, estimate pi = 3.1367
hits : 2157, trials: 3312, estimate pi = 3.0709
hits : 2211, trials: 3413, estimate pi = 3.0873
hits : 2226, trials: 3513, estimate pi = 3.1563
hits : 2286, trials: 3613, estimate pi = 3.1610
hits : 2422, trials: 3713, estimate pi = 3.0661
hits : 2457, trials: 3813, estimate pi = 3.1038
hits : 2517, trials: 3913, estimate pi = 3.1093
hits : 2565, trials: 4013, estimate pi = 3.1290
hits : 2590, trials: 4113, estimate pi = 3.1761
hits : 2702, trials: 4213, estimate pi = 3.1184
hits : 2777, trials: 4313, estimate pi = 3.1062
hits : 2834, trials: 4413, estimate pi = 3.1143
hits : 2886, trials: 4514, estimate pi = 3.1282
hits : 2931, trials: 4614, estimate pi = 3.1484
hits : 3068, trials: 4714, estimate pi = 3.0730
hits : 3078, trials: 4814, estimate pi = 3.1280
hits : 3166, trials: 4914, estimate pi = 3.1042
hits : 3228, trials: 5014, estimate pi = 3.1066
hits : 3256, trials: 5114, estimate pi = 3.1413
hits : 3340, trials: 5214, estimate pi = 3.1222
hits : 3412, trials: 5314, estimate pi = 3.1149
hits : 3444, trials: 5414, estimate pi = 3.1440
hits : 3470, trials: 5514, estimate pi = 3.1781
hits : 3608, trials: 5615, estimate pi = 3.1125
hits : 3717, trials: 5715, estimate pi = 3.0751
hits : 3747, trials: 5815, estimate pi = 3.1038
hits : 3861, trials: 5915, estimate pi = 3.0640
hits : 3847, trials: 6015, estimate pi = 3.1271
hits : 3924, trials: 6115, estimate pi = 3.1167
hits : 4022, trials: 6215, estimate pi = 3.0905
hits : 4050, trials: 6315, estimate pi = 3.1185
hits : 4149, trials: 6415, estimate pi = 3.0923
hits : 4177, trials: 6515, estimate pi = 3.1195
hits : 4334, trials: 6615, estimate pi = 3.0526
hits : 4264, trials: 6716, estimate pi = 3.1501
hits : 4398, trials: 6816, estimate pi = 3.0996
hits : 4381, trials: 6916, estimate pi = 3.1573
hits : 4512, trials: 7016, estimate pi = 3.1099
hits : 4564, trials: 7116, estimate pi = 3.1183
hits : 4715, trials: 7216, estimate pi = 3.0609
hits : 4752, trials: 7316, estimate pi = 3.0791
hits : 4813, trials: 7416, estimate pi = 3.0817
hits : 4861, trials: 7516, estimate pi = 3.0924
hits : 4967, trials: 7616, estimate pi = 3.0666
hits : 4990, trials: 7716, estimate pi = 3.0926
hits : 5033, trials: 7817, estimate pi = 3.1063
hits : 5090, trials: 7917, estimate pi = 3.1108
hits : 5146, trials: 8017, estimate pi = 3.1158
hits : 5276, trials: 8117, estimate pi = 3.0770
hits : 5291, trials: 8217, estimate pi = 3.1060
hits : 5369, trials: 8317, estimate pi = 3.0982
hits : 5426, trials: 8417, estimate pi = 3.1025
hits : 5455, trials: 8517, estimate pi = 3.1226
hits : 5575, trials: 8617, estimate pi = 3.0913
hits : 5692, trials: 8717, estimate pi = 3.0629
hits : 5725, trials: 8817, estimate pi = 3.0802
hits : 5721, trials: 8918, estimate pi = 3.1176
hits : 5823, trials: 9018, estimate pi = 3.0974
hits : 5866, trials: 9118, estimate pi = 3.1088
hits : 5947, trials: 9218, estimate pi = 3.1001
hits : 5994, trials: 9318, estimate pi = 3.1091
hits : 5976, trials: 9418, estimate pi = 3.1519
hits : 6115, trials: 9518, estimate pi = 3.1130
hits : 6149, trials: 9618, estimate pi = 3.1283
hits : 6220, trials: 9718, estimate pi = 3.1248
hits : 6301, trials: 9818, estimate pi = 3.1163
hits : 6303, trials: 9918, estimate pi = 3.1471
hits : 6486, trials: 10019, estimate pi = 3.0894
hits : 6510, trials: 10119, estimate pi = 3.1088
hits : 6443, trials: 10219, estimate pi = 3.1721
hits : 6630, trials: 10319, estimate pi = 3.1128
hits : 6695, trials: 10419, estimate pi = 3.1125
hits : 6688, trials: 10519, estimate pi = 3.1456
hits : 6836, trials: 10619, estimate pi = 3.1068
hits : 6863, trials: 10719, estimate pi = 3.1237
hits : 6957, trials: 10819, estimate pi = 3.1102
hits : 7040, trials: 10919, estimate pi = 3.1020
hits : 7107, trials: 11019, estimate pi = 3.1009
hits : 7039, trials: 11120, estimate pi = 3.1595
hits : 7221, trials: 11220, estimate pi = 3.1076
hits : 7269, trials: 11320, estimate pi = 3.1146
hits : 7394, trials: 11420, estimate pi = 3.0890
hits : 7413, trials: 11520, estimate pi = 3.1081
hits : 7389, trials: 11620, estimate pi = 3.1452
hits : 7544, trials: 11720, estimate pi = 3.1071
hits : 7600, trials: 11820, estimate pi = 3.1105
hits : 7742, trials: 11920, estimate pi = 3.0793
hits : 7779, trials: 12020, estimate pi = 3.0904
hits : 7787, trials: 12120, estimate pi = 3.1129
hits : 7732, trials: 12220, estimate pi = 3.1609
hits : 7877, trials: 12321, estimate pi = 3.1283
hits : 7982, trials: 12421, estimate pi = 3.1123
hits : 8067, trials: 12521, estimate pi = 3.1043
hits : 8175, trials: 12621, estimate pi = 3.0877
hits : 8183, trials: 12721, estimate pi = 3.1091
hits : 8269, trials: 12821, estimate pi = 3.1010
hits : 8329, trials: 12921, estimate pi = 3.1027
hits : 8322, trials: 13021, estimate pi = 3.1293
hits : 8492, trials: 13121, estimate pi = 3.0902
hits : 8558, trials: 13221, estimate pi = 3.0897
hits : 8542, trials: 13321, estimate pi = 3.1189
hits : 8626, trials: 13422, estimate pi = 3.1120
hits : 8752, trials: 13522, estimate pi = 3.0900
hits : 8694, trials: 13622, estimate pi = 3.1337
hits : 8638, trials: 13722, estimate pi = 3.1771
hits : 8820, trials: 13822, estimate pi = 3.1342
hits : 8880, trials: 13922, estimate pi = 3.1356
hits : 9009, trials: 14022, estimate pi = 3.1129
hits : 8986, trials: 14122, estimate pi = 3.1431
hits : 9205, trials: 14222, estimate pi = 3.0901
hits : 9304, trials: 14322, estimate pi = 3.0787
hits : 9179, trials: 14422, estimate pi = 3.1424
hits : 9209, trials: 14523, estimate pi = 3.1541
hits : 9501, trials: 14623, estimate pi = 3.0782
hits : 9508, trials: 14723, estimate pi = 3.0970
hits : 9430, trials: 14823, estimate pi = 3.1438
hits : 9546, trials: 14923, estimate pi = 3.1265
hits : 9537, trials: 15023, estimate pi = 3.1505
hits : 9744, trials: 15123, estimate pi = 3.1041
hits : 9767, trials: 15223, estimate pi = 3.1172
hits : 9806, trials: 15323, estimate pi = 3.1252
hits : 9777, trials: 15423, estimate pi = 3.1550
hits : 10084, trials: 15523, estimate pi = 3.0787
hits : 10059, trials: 15624, estimate pi = 3.1065
hits : 10117, trials: 15724, estimate pi = 3.1084
hits : 10129, trials: 15824, estimate pi = 3.1245
hits : 10330, trials: 15924, estimate pi = 3.0831
hits : 10168, trials: 16024, estimate pi = 3.1518
hits : 10463, trials: 16124, estimate pi = 3.0821
hits : 10453, trials: 16224, estimate pi = 3.1042
hits : 10514, trials: 16324, estimate pi = 3.1052
hits : 10581, trials: 16424, estimate pi = 3.1044
hits : 10613, trials: 16524, estimate pi = 3.1139
hits : 10700, trials: 16624, estimate pi = 3.1073
hits : 10749, trials: 16725, estimate pi = 3.1119
hits : 10901, trials: 16825, estimate pi = 3.0869
hits : 10822, trials: 16925, estimate pi = 3.1279
hits : 10892, trials: 17025, estimate pi = 3.1261
hits : 10958, trials: 17125, estimate pi = 3.1256
hits : 11016, trials: 17225, estimate pi = 3.1273
hits : 11139, trials: 17325, estimate pi = 3.1107
hits : 11216, trials: 17425, estimate pi = 3.1072
hits : 11269, trials: 17525, estimate pi = 3.1103
hits : 11395, trials: 17625, estimate pi = 3.0935
hits : 11379, trials: 17725, estimate pi = 3.1154
hits : 11543, trials: 17826, estimate pi = 3.0886
hits : 11500, trials: 17926, estimate pi = 3.1176
hits : 11680, trials: 18026, estimate pi = 3.0866
hits : 11736, trials: 18126, estimate pi = 3.0890
hits : 11804, trials: 18226, estimate pi = 3.0881
hits : 11789, trials: 18326, estimate pi = 3.1090
hits : 11800, trials: 18426, estimate pi = 3.1231
hits : 11910, trials: 18526, estimate pi = 3.1110
hits : 12072, trials: 18626, estimate pi = 3.0858
hits : 12044, trials: 18726, estimate pi = 3.1096
hits : 11906, trials: 18826, estimate pi = 3.1624
hits : 12231, trials: 18927, estimate pi = 3.0949
hits : 12246, trials: 19027, estimate pi = 3.1075
hits : 12347, trials: 19127, estimate pi = 3.0982
hits : 12327, trials: 19227, estimate pi = 3.1195
hits : 12442, trials: 19327, estimate pi = 3.1067
hits : 12381, trials: 19427, estimate pi = 3.1382
hits : 12619, trials: 19527, estimate pi = 3.0949
hits : 12570, trials: 19627, estimate pi = 3.1228
hits : 12698, trials: 19727, estimate pi = 3.1071
hits : 12638, trials: 19827, estimate pi = 3.1377
hits : 12750, trials: 19927, estimate pi = 3.1258
hits : 12936, trials: 20028, estimate pi = 3.0965
hits : 12966, trials: 20128, estimate pi = 3.1047
hits : 13038, trials: 20228, estimate pi = 3.1029
hits : 13040, trials: 20328, estimate pi = 3.1178
hits : 13149, trials: 20428, estimate pi = 3.1072
hits : 13016, trials: 20528, estimate pi = 3.1543
hits : 13294, trials: 20628, estimate pi = 3.1034
hits : 13170, trials: 20728, estimate pi = 3.1478
hits : 13501, trials: 20828, estimate pi = 3.0854
hits : 13561, trials: 20928, estimate pi = 3.0865
hits : 13548, trials: 21028, estimate pi = 3.1042
hits : 13564, trials: 21129, estimate pi = 3.1155
hits : 13637, trials: 21229, estimate pi = 3.1134
hits : 13769, trials: 21329, estimate pi = 3.0981
hits : 13726, trials: 21429, estimate pi = 3.1224
hits : 13858, trials: 21529, estimate pi = 3.1071
hits : 13911, trials: 21629, estimate pi = 3.1096
hits : 13768, trials: 21729, estimate pi = 3.1564
hits : 13927, trials: 21829, estimate pi = 3.1348
hits : 14093, trials: 21929, estimate pi = 3.1120
hits : 14070, trials: 22029, estimate pi = 3.1313
hits : 14230, trials: 22129, estimate pi = 3.1102
hits : 14229, trials: 22230, estimate pi = 3.1246
hits : 14297, trials: 22330, estimate pi = 3.1237
hits : 14194, trials: 22430, estimate pi = 3.1605
hits : 14365, trials: 22530, estimate pi = 3.1368
hits : 14570, trials: 22630, estimate pi = 3.1064
hits : 14559, trials: 22730, estimate pi = 3.1225
hits : 14645, trials: 22830, estimate pi = 3.1178
hits : 14751, trials: 22930, estimate pi = 3.1089
hits : 14728, trials: 23030, estimate pi = 3.1274
hits : 14808, trials: 23130, estimate pi = 3.1240
hits : 14871, trials: 23230, estimate pi = 3.1242
hits : 14911, trials: 23330, estimate pi = 3.1292
hits : 15000, trials: 23431, estimate pi = 3.1241
hits : 15145, trials: 23531, estimate pi = 3.1074
hits : 15099, trials: 23631, estimate pi = 3.1301
hits : 15265, trials: 23731, estimate pi = 3.1092
hits : 15271, trials: 23831, estimate pi = 3.1211
hits : 15263, trials: 23931, estimate pi = 3.1358
hits : 15465, trials: 24031, estimate pi = 3.1078
hits : 15500, trials: 24131, estimate pi = 3.1137
hits : 15569, trials: 24231, estimate pi = 3.1127
hits : 15638, trials: 24331, estimate pi = 3.1118
hits : 15796, trials: 24431, estimate pi = 3.0933
hits : 15694, trials: 24532, estimate pi = 3.1263
hits : 15919, trials: 24632, estimate pi = 3.0947
hits : 15922, trials: 24732, estimate pi = 3.1066
hits : 15966, trials: 24832, estimate pi = 3.1106
hits : 15959, trials: 24932, estimate pi = 3.1245
hits : 16058, trials: 25032, estimate pi = 3.1177
hits : 16184, trials: 25132, estimate pi = 3.1058
hits : 16162, trials: 25232, estimate pi = 3.1224
hits : 16321, trials: 25332, estimate pi = 3.1042
hits : 16435, trials: 25432, estimate pi = 3.0949
hits : 16440, trials: 25532, estimate pi = 3.1061
hits : 16491, trials: 25633, estimate pi = 3.1087
hits : 16520, trials: 25733, estimate pi = 3.1154
hits : 16613, trials: 25833, estimate pi = 3.1100
hits : 16707, trials: 25933, estimate pi = 3.1044
hits : 16692, trials: 26033, estimate pi = 3.1192
hits : 16915, trials: 26133, estimate pi = 3.0899
hits : 16734, trials: 26233, estimate pi = 3.1353
hits : 16819, trials: 26333, estimate pi = 3.1313
hits : 17000, trials: 26433, estimate pi = 3.1098
hits : 17104, trials: 26533, estimate pi = 3.1025
hits : 17137, trials: 26633, estimate pi = 3.1082
hits : 17141, trials: 26734, estimate pi = 3.1193
hits : 17111, trials: 26834, estimate pi = 3.1365
hits : 17458, trials: 26934, estimate pi = 3.0856
hits : 17307, trials: 27034, estimate pi = 3.1241
hits : 17276, trials: 27134, estimate pi = 3.1412
hits : 17441, trials: 27234, estimate pi = 3.1230
hits : 17464, trials: 27334, estimate pi = 3.1303
hits : 17493, trials: 27434, estimate pi = 3.1366
hits : 17661, trials: 27534, estimate pi = 3.1181
hits : 17799, trials: 27634, estimate pi = 3.1051
hits : 17871, trials: 27734, estimate pi = 3.1038
hits : 17977, trials: 27835, estimate pi = 3.0967
hits : 18135, trials: 27935, estimate pi = 3.0808
hits : 17927, trials: 28035, estimate pi = 3.1277
hits : 18164, trials: 28135, estimate pi = 3.0979
hits : 18165, trials: 28235, estimate pi = 3.1087
hits : 18198, trials: 28335, estimate pi = 3.1141
hits : 18270, trials: 28435, estimate pi = 3.1128
hits : 18394, trials: 28535, estimate pi = 3.1026
hits : 18247, trials: 28635, estimate pi = 3.1386
hits : 18465, trials: 28735, estimate pi = 3.1124
hits : 18349, trials: 28835, estimate pi = 3.1430
hits : 18476, trials: 28936, estimate pi = 3.1323
hits : 18547, trials: 29036, estimate pi = 3.1311
hits : 18744, trials: 29136, estimate pi = 3.1088
hits : 18820, trials: 29236, estimate pi = 3.1069
hits : 19034, trials: 29336, estimate pi = 3.0825
hits : 18950, trials: 29436, estimate pi = 3.1067
hits : 19070, trials: 29536, estimate pi = 3.0976
hits : 18936, trials: 29636, estimate pi = 3.1301
hits : 19160, trials: 29736, estimate pi = 3.1040
hits : 19064, trials: 29836, estimate pi = 3.1301
hits : 19186, trials: 29936, estimate pi = 3.1206
hits : 19497, trials: 30037, estimate pi = 3.0812
hits : 19504, trials: 30137, estimate pi = 3.0903
hits : 19397, trials: 30237, estimate pi = 3.1177
hits : 19471, trials: 30337, estimate pi = 3.1161
hits : 19522, trials: 30437, estimate pi = 3.1182
hits : 19676, trials: 30537, estimate pi = 3.1040
hits : 19707, trials: 30637, estimate pi = 3.1093
hits : 19821, trials: 30737, estimate pi = 3.1015
hits : 19822, trials: 30837, estimate pi = 3.1114
hits : 19972, trials: 30937, estimate pi = 3.0980
hits : 19861, trials: 31037, estimate pi = 3.1254
hits : 20044, trials: 31138, estimate pi = 3.1070
hits : 20067, trials: 31238, estimate pi = 3.1134
hits : 20018, trials: 31338, estimate pi = 3.1310
hits : 20135, trials: 31438, estimate pi = 3.1227
hits : 20374, trials: 31538, estimate pi = 3.0959
hits : 20108, trials: 31638, estimate pi = 3.1468
hits : 20455, trials: 31738, estimate pi = 3.1032
hits : 20432, trials: 31838, estimate pi = 3.1165
hits : 20548, trials: 31938, estimate pi = 3.1086
hits : 20481, trials: 32038, estimate pi = 3.1286
hits : 20598, trials: 32138, estimate pi = 3.1205
hits : 20708, trials: 32239, estimate pi = 3.1137
hits : 20759, trials: 32339, estimate pi = 3.1157
hits : 20852, trials: 32439, estimate pi = 3.1114
hits : 20857, trials: 32539, estimate pi = 3.1202
hits : 20855, trials: 32639, estimate pi = 3.1301
hits : 21107, trials: 32739, estimate pi = 3.1022
hits : 21164, trials: 32839, estimate pi = 3.1033
hits : 21166, trials: 32939, estimate pi = 3.1124
hits : 21254, trials: 33039, estimate pi = 3.1090
hits : 21227, trials: 33139, estimate pi = 3.1223
hits : 21252, trials: 33239, estimate pi = 3.1281
hits : 21521, trials: 33340, estimate pi = 3.0984
hits : 21380, trials: 33440, estimate pi = 3.1282
hits : 21575, trials: 33540, estimate pi = 3.1092
hits : 21686, trials: 33640, estimate pi = 3.1025
hits : 21538, trials: 33740, estimate pi = 3.1331
hits : 21802, trials: 33840, estimate pi = 3.1043
hits : 21766, trials: 33940, estimate pi = 3.1186
hits : 21790, trials: 34040, estimate pi = 3.1244
hits : 21829, trials: 34140, estimate pi = 3.1279
hits : 21960, trials: 34240, estimate pi = 3.1184
hits : 22081, trials: 34340, estimate pi = 3.1104
hits : 22033, trials: 34440, estimate pi = 3.1262
hits : 22231, trials: 34541, estimate pi = 3.1075
hits : 22307, trials: 34641, estimate pi = 3.1058
hits : 22460, trials: 34741, estimate pi = 3.0936
hits : 22437, trials: 34841, estimate pi = 3.1057
hits : 22405, trials: 34941, estimate pi = 3.1190
hits : 22471, trials: 35041, estimate pi = 3.1188
hits : 22625, trials: 35141, estimate pi = 3.1064
hits : 22504, trials: 35241, estimate pi = 3.1320
hits : 22794, trials: 35341, estimate pi = 3.1009
hits : 22711, trials: 35441, estimate pi = 3.1210
hits : 22885, trials: 35541, estimate pi = 3.1061
hits : 22867, trials: 35642, estimate pi = 3.1173
hits : 22910, trials: 35742, estimate pi = 3.1202
hits : 22960, trials: 35842, estimate pi = 3.1221
hits : 22956, trials: 35942, estimate pi = 3.1314
hits : 22987, trials: 36042, estimate pi = 3.1359
hits : 23118, trials: 36142, estimate pi = 3.1267
hits : 23307, trials: 36242, estimate pi = 3.1100
hits : 23308, trials: 36342, estimate pi = 3.1184
hits : 23344, trials: 36442, estimate pi = 3.1222
hits : 23574, trials: 36542, estimate pi = 3.1002
hits : 23502, trials: 36642, estimate pi = 3.1182
hits : 23606, trials: 36743, estimate pi = 3.1130
hits : 23787, trials: 36843, estimate pi = 3.0977
hits : 23669, trials: 36943, estimate pi = 3.1216
hits : 23927, trials: 37043, estimate pi = 3.0963
hits : 23756, trials: 37143, estimate pi = 3.1270
hits : 23675, trials: 37243, estimate pi = 3.1462
hits : 23874, trials: 37343, estimate pi = 3.1283
hits : 24108, trials: 37443, estimate pi = 3.1063
hits : 24288, trials: 37543, estimate pi = 3.0915
hits : 24098, trials: 37643, estimate pi = 3.1242
hits : 24387, trials: 37743, estimate pi = 3.0953
hits : 24250, trials: 37844, estimate pi = 3.1212
hits : 24349, trials: 37944, estimate pi = 3.1167
hits : 24359, trials: 38044, estimate pi = 3.1236
hits : 24371, trials: 38144, estimate pi = 3.1303
hits : 24512, trials: 38244, estimate pi = 3.1204
hits : 24518, trials: 38344, estimate pi = 3.1278
hits : 24613, trials: 38444, estimate pi = 3.1239
hits : 24577, trials: 38544, estimate pi = 3.1366
hits : 24824, trials: 38644, estimate pi = 3.1134
hits : 24812, trials: 38744, estimate pi = 3.1230
hits : 24816, trials: 38844, estimate pi = 3.1306
hits : 24913, trials: 38945, estimate pi = 3.1265
hits : 25110, trials: 39045, estimate pi = 3.1099
hits : 25148, trials: 39145, estimate pi = 3.1132
hits : 25115, trials: 39245, estimate pi = 3.1252
hits : 25152, trials: 39345, estimate pi = 3.1286
hits : 25395, trials: 39445, estimate pi = 3.1065
hits : 25487, trials: 39545, estimate pi = 3.1032
hits : 25453, trials: 39645, estimate pi = 3.1152
hits : 25411, trials: 39745, estimate pi = 3.1282
hits : 25503, trials: 39845, estimate pi = 3.1247
hits : 25639, trials: 39945, estimate pi = 3.1160
hits : 25664, trials: 40046, estimate pi = 3.1208
hits : 25767, trials: 40146, estimate pi = 3.1161
hits : 25805, trials: 40246, estimate pi = 3.1192
hits : 26000, trials: 40346, estimate pi = 3.1035
hits : 25976, trials: 40446, estimate pi = 3.1141
hits : 25985, trials: 40546, estimate pi = 3.1207
hits : 25966, trials: 40646, estimate pi = 3.1307
hits : 26174, trials: 40746, estimate pi = 3.1135
hits : 26304, trials: 40846, estimate pi = 3.1057
hits : 26176, trials: 40946, estimate pi = 3.1285
hits : 26345, trials: 41046, estimate pi = 3.1160
hits : 26341, trials: 41147, estimate pi = 3.1242
hits : 26473, trials: 41247, estimate pi = 3.1162
hits : 26635, trials: 41347, estimate pi = 3.1047
hits : 26763, trials: 41447, estimate pi = 3.0973
hits : 26631, trials: 41547, estimate pi = 3.1202
hits : 26728, trials: 41647, estimate pi = 3.1164
hits : 26985, trials: 41747, estimate pi = 3.0941
hits : 26941, trials: 41847, estimate pi = 3.1066
hits : 26720, trials: 41947, estimate pi = 3.1397
hits : 26855, trials: 42047, estimate pi = 3.1314
hits : 27258, trials: 42147, estimate pi = 3.0924
hits : 27097, trials: 42248, estimate pi = 3.1183
hits : 27338, trials: 42348, estimate pi = 3.0981
hits : 27242, trials: 42448, estimate pi = 3.1164
hits : 27007, trials: 42548, estimate pi = 3.1509
hits : 27512, trials: 42648, estimate pi = 3.1003
hits : 27561, trials: 42748, estimate pi = 3.1021
hits : 27478, trials: 42848, estimate pi = 3.1187
hits : 27718, trials: 42948, estimate pi = 3.0989
hits : 27903, trials: 43048, estimate pi = 3.0855
hits : 27687, trials: 43148, estimate pi = 3.1168
hits : 27775, trials: 43248, estimate pi = 3.1142
hits : 27966, trials: 43349, estimate pi = 3.1001
hits : 27871, trials: 43449, estimate pi = 3.1179
hits : 27970, trials: 43549, estimate pi = 3.1140
hits : 27924, trials: 43649, estimate pi = 3.1263
hits : 28145, trials: 43749, estimate pi = 3.1088
hits : 28350, trials: 43849, estimate pi = 3.0934
hits : 28006, trials: 43949, estimate pi = 3.1385
hits : 28344, trials: 44049, estimate pi = 3.1082
hits : 28271, trials: 44149, estimate pi = 3.1233
hits : 28455, trials: 44249, estimate pi = 3.1101
hits : 28565, trials: 44349, estimate pi = 3.1051
hits : 28506, trials: 44450, estimate pi = 3.1186
hits : 28775, trials: 44550, estimate pi = 3.0964
hits : 28660, trials: 44650, estimate pi = 3.1158
hits : 28901, trials: 44750, estimate pi = 3.0968
hits : 28761, trials: 44850, estimate pi = 3.1188
hits : 28766, trials: 44950, estimate pi = 3.1252
hits : 28991, trials: 45050, estimate pi = 3.1079
hits : 29128, trials: 45150, estimate pi = 3.1001
hits : 29029, trials: 45250, estimate pi = 3.1176
hits : 29274, trials: 45350, estimate pi = 3.0983
hits : 29270, trials: 45450, estimate pi = 3.1056
hits : 29329, trials: 45550, estimate pi = 3.1061
hits : 29324, trials: 45651, estimate pi = 3.1136
hits : 29350, trials: 45751, estimate pi = 3.1176
hits : 29221, trials: 45851, estimate pi = 3.1382
hits : 29546, trials: 45951, estimate pi = 3.1105
hits : 29455, trials: 46051, estimate pi = 3.1269
hits : 29599, trials: 46151, estimate pi = 3.1184
hits : 29667, trials: 46251, estimate pi = 3.1180
hits : 29736, trials: 46351, estimate pi = 3.1175
hits : 29618, trials: 46451, estimate pi = 3.1367
hits : 29953, trials: 46551, estimate pi = 3.1083
hits : 29887, trials: 46651, estimate pi = 3.1218
hits : 30030, trials: 46752, estimate pi = 3.1137
hits : 30064, trials: 46852, estimate pi = 3.1168
hits : 30198, trials: 46952, estimate pi = 3.1096
hits : 30151, trials: 47052, estimate pi = 3.1211
hits : 30374, trials: 47152, estimate pi = 3.1048
hits : 30203, trials: 47252, estimate pi = 3.1290
hits : 30504, trials: 47352, estimate pi = 3.1046
hits : 30496, trials: 47452, estimate pi = 3.1120
hits : 30486, trials: 47552, estimate pi = 3.1196
hits : 30422, trials: 47652, estimate pi = 3.1327
hits : 30642, trials: 47752, estimate pi = 3.1168
hits : 30988, trials: 47853, estimate pi = 3.0885
hits : 30813, trials: 47953, estimate pi = 3.1125
hits : 30764, trials: 48053, estimate pi = 3.1240
hits : 30866, trials: 48153, estimate pi = 3.1201
hits : 30977, trials: 48253, estimate pi = 3.1154
hits : 31117, trials: 48353, estimate pi = 3.1078
hits : 31049, trials: 48453, estimate pi = 3.1211
hits : 31218, trials: 48553, estimate pi = 3.1106
hits : 31417, trials: 48653, estimate pi = 3.0972
hits : 31292, trials: 48753, estimate pi = 3.1160
hits : 31322, trials: 48853, estimate pi = 3.1194
hits : 31256, trials: 48954, estimate pi = 3.1325
hits : 31555, trials: 49054, estimate pi = 3.1091
hits : 31643, trials: 49154, estimate pi = 3.1068
hits : 31688, trials: 49254, estimate pi = 3.1087
hits : 31715, trials: 49354, estimate pi = 3.1123
hits : 31812, trials: 49454, estimate pi = 3.1091
hits : 31821, trials: 49554, estimate pi = 3.1145
hits : 31845, trials: 49654, estimate pi = 3.1185
hits : 31920, trials: 49754, estimate pi = 3.1174
hits : 31976, trials: 49854, estimate pi = 3.1182
hits : 32056, trials: 49954, estimate pi = 3.1167
hits : 32352, trials: 50055, estimate pi = 3.0944
hits : 32197, trials: 50155, estimate pi = 3.1155
hits : 32464, trials: 50255, estimate pi = 3.0960
hits : 32371, trials: 50355, estimate pi = 3.1111
hits : 32634, trials: 50455, estimate pi = 3.0922
hits : 32394, trials: 50555, estimate pi = 3.1213
hits : 32675, trials: 50655, estimate pi = 3.1005
hits : 32641, trials: 50755, estimate pi = 3.1099
hits : 32528, trials: 50855, estimate pi = 3.1268
hits : 32850, trials: 50955, estimate pi = 3.1023
hits : 32947, trials: 51055, estimate pi = 3.0992
hits : 32777, trials: 51156, estimate pi = 3.1215
hits : 33015, trials: 51256, estimate pi = 3.1050
hits : 32732, trials: 51356, estimate pi = 3.1380
hits : 33164, trials: 51456, estimate pi = 3.1031
hits : 33304, trials: 51556, estimate pi = 3.0961
hits : 33183, trials: 51656, estimate pi = 3.1134
hits : 33122, trials: 51756, estimate pi = 3.1252
hits : 33237, trials: 51856, estimate pi = 3.1204
hits : 33224, trials: 51956, estimate pi = 3.1276
hits : 33583, trials: 52056, estimate pi = 3.1001
hits : 33517, trials: 52156, estimate pi = 3.1122
hits : 33409, trials: 52257, estimate pi = 3.1283
hits : 33552, trials: 52357, estimate pi = 3.1209
hits : 33722, trials: 52457, estimate pi = 3.1111
hits : 33692, trials: 52557, estimate pi = 3.1199
hits : 33582, trials: 52657, estimate pi = 3.1360
hits : 34031, trials: 52757, estimate pi = 3.1005
hits : 33895, trials: 52857, estimate pi = 3.1189
hits : 33941, trials: 52957, estimate pi = 3.1205
hits : 34215, trials: 53057, estimate pi = 3.1014
hits : 34001, trials: 53157, estimate pi = 3.1268
hits : 34385, trials: 53257, estimate pi = 3.0977
hits : 34233, trials: 53358, estimate pi = 3.1173
hits : 34451, trials: 53458, estimate pi = 3.1034
hits : 34157, trials: 53558, estimate pi = 3.1360
hits : 34553, trials: 53658, estimate pi = 3.1058
hits : 34629, trials: 53758, estimate pi = 3.1048
hits : 34556, trials: 53858, estimate pi = 3.1171
hits : 34785, trials: 53958, estimate pi = 3.1024
hits : 34847, trials: 54058, estimate pi = 3.1026
hits : 34846, trials: 54158, estimate pi = 3.1084
hits : 34915, trials: 54258, estimate pi = 3.1080
hits : 34813, trials: 54358, estimate pi = 3.1229
hits : 34994, trials: 54459, estimate pi = 3.1125
hits : 34997, trials: 54559, estimate pi = 3.1179
hits : 35184, trials: 54659, estimate pi = 3.1070
hits : 35151, trials: 54759, estimate pi = 3.1156
hits : 35117, trials: 54859, estimate pi = 3.1244
hits : 35432, trials: 54959, estimate pi = 3.1022
hits : 35535, trials: 55059, estimate pi = 3.0989
hits : 35517, trials: 55159, estimate pi = 3.1061
hits : 35309, trials: 55259, estimate pi = 3.1300
hits : 35519, trials: 55359, estimate pi = 3.1171
hits : 35575, trials: 55459, estimate pi = 3.1179
hits : 35687, trials: 55560, estimate pi = 3.1137
hits : 35734, trials: 55660, estimate pi = 3.1152
hits : 35866, trials: 55760, estimate pi = 3.1094
hits : 35957, trials: 55860, estimate pi = 3.1070
hits : 35943, trials: 55960, estimate pi = 3.1138
hits : 36174, trials: 56060, estimate pi = 3.0995
hits : 36118, trials: 56160, estimate pi = 3.1098
hits : 36196, trials: 56260, estimate pi = 3.1086
hits : 36212, trials: 56360, estimate pi = 3.1128
hits : 36147, trials: 56460, estimate pi = 3.1239
hits : 36148, trials: 56560, estimate pi = 3.1294
hits : 36199, trials: 56660, estimate pi = 3.1305
hits : 36514, trials: 56761, estimate pi = 3.1090
hits : 36487, trials: 56861, estimate pi = 3.1168
hits : 36808, trials: 56961, estimate pi = 3.0950
hits : 36911, trials: 57061, estimate pi = 3.0918
hits : 36761, trials: 57161, estimate pi = 3.1099
hits : 36707, trials: 57261, estimate pi = 3.1199
hits : 37036, trials: 57361, estimate pi = 3.0976
hits : 36836, trials: 57461, estimate pi = 3.1198
hits : 37084, trials: 57561, estimate pi = 3.1044
hits : 36868, trials: 57661, estimate pi = 3.1280
hits : 36846, trials: 57761, estimate pi = 3.1353
hits : 37054, trials: 57862, estimate pi = 3.1231
hits : 37187, trials: 57962, estimate pi = 3.1173
hits : 37425, trials: 58062, estimate pi = 3.1028
hits : 37380, trials: 58162, estimate pi = 3.1119
hits : 37299, trials: 58262, estimate pi = 3.1241
hits : 37323, trials: 58362, estimate pi = 3.1274
hits : 37524, trials: 58462, estimate pi = 3.1160
hits : 37528, trials: 58562, estimate pi = 3.1210
hits : 37669, trials: 58662, estimate pi = 3.1146
hits : 37871, trials: 58762, estimate pi = 3.1033
hits : 37978, trials: 58862, estimate pi = 3.0998
hits : 38003, trials: 58963, estimate pi = 3.1031
hits : 37869, trials: 59063, estimate pi = 3.1193
hits : 38081, trials: 59163, estimate pi = 3.1072
hits : 38011, trials: 59263, estimate pi = 3.1182
hits : 38139, trials: 59363, estimate pi = 3.1130
hits : 38202, trials: 59463, estimate pi = 3.1131
hits : 38397, trials: 59563, estimate pi = 3.1025
hits : 38462, trials: 59663, estimate pi = 3.1024
hits : 38274, trials: 59763, estimate pi = 3.1229
hits : 38409, trials: 59863, estimate pi = 3.1171
hits : 38414, trials: 59963, estimate pi = 3.1219
hits : 38538, trials: 60064, estimate pi = 3.1171
hits : 38404, trials: 60164, estimate pi = 3.1332
hits : 38645, trials: 60264, estimate pi = 3.1189
hits : 38710, trials: 60364, estimate pi = 3.1188
hits : 38825, trials: 60464, estimate pi = 3.1147
hits : 38982, trials: 60564, estimate pi = 3.1073
hits : 38958, trials: 60664, estimate pi = 3.1143
hits : 38980, trials: 60764, estimate pi = 3.1177
hits : 38763, trials: 60864, estimate pi = 3.1403
hits : 39223, trials: 60964, estimate pi = 3.1086
hits : 39102, trials: 61064, estimate pi = 3.1233
hits : 39096, trials: 61165, estimate pi = 3.1290
hits : 39433, trials: 61265, estimate pi = 3.1073
hits : 39466, trials: 61365, estimate pi = 3.1098
hits : 39419, trials: 61465, estimate pi = 3.1185
hits : 39478, trials: 61565, estimate pi = 3.1190
hits : 39487, trials: 61665, estimate pi = 3.1233
hits : 39992, trials: 61765, estimate pi = 3.0889
hits : 39822, trials: 61865, estimate pi = 3.1071
hits : 39834, trials: 61965, estimate pi = 3.1112
hits : 39860, trials: 62065, estimate pi = 3.1141
hits : 39963, trials: 62165, estimate pi = 3.1111
hits : 39925, trials: 62266, estimate pi = 3.1191
hits : 40097, trials: 62366, estimate pi = 3.1108
hits : 40115, trials: 62466, estimate pi = 3.1143
hits : 40377, trials: 62566, estimate pi = 3.0991
hits : 40111, trials: 62666, estimate pi = 3.1246
hits : 40265, trials: 62766, estimate pi = 3.1176
hits : 40361, trials: 62866, estimate pi = 3.1152
hits : 40231, trials: 62966, estimate pi = 3.1302
hits : 40518, trials: 63066, estimate pi = 3.1130
hits : 40554, trials: 63166, estimate pi = 3.1152
hits : 40362, trials: 63266, estimate pi = 3.1349
hits : 40803, trials: 63367, estimate pi = 3.1060
hits : 40830, trials: 63467, estimate pi = 3.1088
hits : 40947, trials: 63567, estimate pi = 3.1048
hits : 40813, trials: 63667, estimate pi = 3.1199
hits : 41069, trials: 63767, estimate pi = 3.1054
hits : 41089, trials: 63867, estimate pi = 3.1087
hits : 41122, trials: 63967, estimate pi = 3.1111
hits : 41247, trials: 64067, estimate pi = 3.1065
hits : 41285, trials: 64167, estimate pi = 3.1085
hits : 41023, trials: 64267, estimate pi = 3.1332
hits : 41359, trials: 64367, estimate pi = 3.1126
hits : 41239, trials: 64468, estimate pi = 3.1266
hits : 41426, trials: 64568, estimate pi = 3.1173
hits : 41589, trials: 64668, estimate pi = 3.1099
hits : 41516, trials: 64768, estimate pi = 3.1201
hits : 41648, trials: 64868, estimate pi = 3.1151
hits : 41565, trials: 64968, estimate pi = 3.1261
hits : 41764, trials: 65068, estimate pi = 3.1160
hits : 41815, trials: 65168, estimate pi = 3.1170
hits : 41955, trials: 65268, estimate pi = 3.1113
hits : 42026, trials: 65368, estimate pi = 3.1108
hits : 42169, trials: 65468, estimate pi = 3.1050
hits : 42276, trials: 65569, estimate pi = 3.1019
hits : 42060, trials: 65669, estimate pi = 3.1226
hits : 42317, trials: 65769, estimate pi = 3.1084
hits : 42639, trials: 65869, estimate pi = 3.0896
hits : 42457, trials: 65969, estimate pi = 3.1076
hits : 42530, trials: 66069, estimate pi = 3.1069
hits : 42506, trials: 66169, estimate pi = 3.1134
hits : 42726, trials: 66269, estimate pi = 3.1020
hits : 42659, trials: 66369, estimate pi = 3.1116
hits : 42416, trials: 66469, estimate pi = 3.1341
hits : 42768, trials: 66569, estimate pi = 3.1130
hits : 42947, trials: 66670, estimate pi = 3.1048
hits : 43012, trials: 66770, estimate pi = 3.1047
hits : 42834, trials: 66870, estimate pi = 3.1223
hits : 42973, trials: 66970, estimate pi = 3.1168
hits : 42978, trials: 67070, estimate pi = 3.1211
hits : 43191, trials: 67170, estimate pi = 3.1104
hits : 43067, trials: 67270, estimate pi = 3.1240
hits : 43381, trials: 67370, estimate pi = 3.1060
hits : 43358, trials: 67470, estimate pi = 3.1122
hits : 43343, trials: 67570, estimate pi = 3.1179
hits : 43532, trials: 67670, estimate pi = 3.1090
hits : 43676, trials: 67770, estimate pi = 3.1033
hits : 43337, trials: 67871, estimate pi = 3.1322
hits : 43445, trials: 67971, estimate pi = 3.1291
hits : 43786, trials: 68071, estimate pi = 3.1093
hits : 43824, trials: 68171, estimate pi = 3.1111
hits : 44006, trials: 68271, estimate pi = 3.1028
hits : 43983, trials: 68371, estimate pi = 3.1090
hits : 43841, trials: 68471, estimate pi = 3.1236
hits : 44043, trials: 68571, estimate pi = 3.1138
hits : 44264, trials: 68671, estimate pi = 3.1028
hits : 44336, trials: 68771, estimate pi = 3.1023
hits : 44292, trials: 68871, estimate pi = 3.1099
hits : 44303, trials: 68972, estimate pi = 3.1136
hits : 44507, trials: 69072, estimate pi = 3.1039
hits : 44522, trials: 69172, estimate pi = 3.1073
hits : 44614, trials: 69272, estimate pi = 3.1054
hits : 44687, trials: 69372, estimate pi = 3.1048
hits : 44447, trials: 69472, estimate pi = 3.1261
hits : 44634, trials: 69572, estimate pi = 3.1174
hits : 44724, trials: 69672, estimate pi = 3.1156
hits : 44737, trials: 69772, estimate pi = 3.1192
hits : 44942, trials: 69872, estimate pi = 3.1094
hits : 44739, trials: 69972, estimate pi = 3.1280
hits : 45076, trials: 70073, estimate pi = 3.1091
hits : 45040, trials: 70173, estimate pi = 3.1160
hits : 45296, trials: 70273, estimate pi = 3.1028
hits : 45176, trials: 70373, estimate pi = 3.1155
hits : 45115, trials: 70473, estimate pi = 3.1241
hits : 45378, trials: 70573, estimate pi = 3.1104
hits : 45726, trials: 70673, estimate pi = 3.0912
hits : 45644, trials: 70773, estimate pi = 3.1011
hits : 45333, trials: 70873, estimate pi = 3.1268
hits : 45489, trials: 70973, estimate pi = 3.1204
hits : 45567, trials: 71073, estimate pi = 3.1195
hits : 45924, trials: 71174, estimate pi = 3.0996
hits : 45805, trials: 71274, estimate pi = 3.1121
hits : 45702, trials: 71374, estimate pi = 3.1235
hits : 45723, trials: 71474, estimate pi = 3.1264
hits : 46013, trials: 71574, estimate pi = 3.1110
hits : 45935, trials: 71674, estimate pi = 3.1207
hits : 46075, trials: 71774, estimate pi = 3.1155
hits : 46345, trials: 71874, estimate pi = 3.1017
hits : 46231, trials: 71974, estimate pi = 3.1137
hits : 46285, trials: 72074, estimate pi = 3.1144
hits : 46357, trials: 72174, estimate pi = 3.1138
hits : 46300, trials: 72275, estimate pi = 3.1220
hits : 46478, trials: 72375, estimate pi = 3.1144
hits : 46776, trials: 72475, estimate pi = 3.0988
hits : 46674, trials: 72575, estimate pi = 3.1099
hits : 46563, trials: 72675, estimate pi = 3.1216
hits : 46744, trials: 72775, estimate pi = 3.1138
hits : 46883, trials: 72875, estimate pi = 3.1088
hits : 46988, trials: 72975, estimate pi = 3.1061
hits : 46581, trials: 73075, estimate pi = 3.1375
hits : 47151, trials: 73175, estimate pi = 3.1039
hits : 47184, trials: 73275, estimate pi = 3.1059
hits : 47312, trials: 73376, estimate pi = 3.1018
hits : 47030, trials: 73476, estimate pi = 3.1246
hits : 47254, trials: 73576, estimate pi = 3.1141
hits : 47260, trials: 73676, estimate pi = 3.1179
hits : 47226, trials: 73776, estimate pi = 3.1244
hits : 47391, trials: 73876, estimate pi = 3.1177
hits : 47675, trials: 73976, estimate pi = 3.1033
hits : 47516, trials: 74076, estimate pi = 3.1179
hits : 47671, trials: 74176, estimate pi = 3.1120
hits : 47950, trials: 74276, estimate pi = 3.0981
hits : 47781, trials: 74376, estimate pi = 3.1132
hits : 48070, trials: 74477, estimate pi = 3.0987
hits : 47806, trials: 74577, estimate pi = 3.1200
hits : 47844, trials: 74677, estimate pi = 3.1217
hits : 47992, trials: 74777, estimate pi = 3.1162
hits : 48091, trials: 74877, estimate pi = 3.1140
hits : 48271, trials: 74977, estimate pi = 3.1065
hits : 48190, trials: 75077, estimate pi = 3.1159
hits : 48430, trials: 75177, estimate pi = 3.1046
hits : 48374, trials: 75277, estimate pi = 3.1123
hits : 48215, trials: 75377, estimate pi = 3.1267
hits : 48198, trials: 75477, estimate pi = 3.1320
hits : 48730, trials: 75578, estimate pi = 3.1019
hits : 48476, trials: 75678, estimate pi = 3.1223
hits : 48725, trials: 75778, estimate pi = 3.1104
hits : 48865, trials: 75878, estimate pi = 3.1056
hits : 48836, trials: 75978, estimate pi = 3.1116
hits : 48801, trials: 76078, estimate pi = 3.1179
hits : 49019, trials: 76178, estimate pi = 3.1081
hits : 49056, trials: 76278, estimate pi = 3.1098
hits : 48738, trials: 76378, estimate pi = 3.1342
hits : 49214, trials: 76478, estimate pi = 3.1080
hits : 49278, trials: 76578, estimate pi = 3.1080
hits : 49199, trials: 76679, estimate pi = 3.1171
hits : 48990, trials: 76779, estimate pi = 3.1345
hits : 49530, trials: 76879, estimate pi = 3.1043
hits : 49406, trials: 76979, estimate pi = 3.1162
hits : 49441, trials: 77079, estimate pi = 3.1180
hits : 49652, trials: 77179, estimate pi = 3.1088
hits : 49671, trials: 77279, estimate pi = 3.1116
hits : 49709, trials: 77379, estimate pi = 3.1133
hits : 49896, trials: 77479, estimate pi = 3.1056
hits : 49866, trials: 77579, estimate pi = 3.1115
hits : 49846, trials: 77679, estimate pi = 3.1168
hits : 50097, trials: 77780, estimate pi = 3.1052
hits : 50177, trials: 77880, estimate pi = 3.1042
hits : 50131, trials: 77980, estimate pi = 3.1110
hits : 50042, trials: 78080, estimate pi = 3.1206
hits : 50278, trials: 78180, estimate pi = 3.1099
hits : 50201, trials: 78280, estimate pi = 3.1187
hits : 50378, trials: 78380, estimate pi = 3.1117
hits : 50514, trials: 78480, estimate pi = 3.1073
hits : 50531, trials: 78580, estimate pi = 3.1102
hits : 50490, trials: 78680, estimate pi = 3.1167
hits : 50579, trials: 78780, estimate pi = 3.1151
hits : 50928, trials: 78880, estimate pi = 3.0977
hits : 50757, trials: 78981, estimate pi = 3.1121
hits : 50660, trials: 79081, estimate pi = 3.1220
hits : 50692, trials: 79181, estimate pi = 3.1240
hits : 50792, trials: 79281, estimate pi = 3.1218
hits : 50991, trials: 79381, estimate pi = 3.1135
hits : 51125, trials: 79481, estimate pi = 3.1093
hits : 51096, trials: 79581, estimate pi = 3.1150
hits : 51336, trials: 79681, estimate pi = 3.1043
hits : 51044, trials: 79781, estimate pi = 3.1260
hits : 51228, trials: 79881, estimate pi = 3.1186
hits : 51212, trials: 79981, estimate pi = 3.1235
hits : 51426, trials: 80082, estimate pi = 3.1145
hits : 51521, trials: 80182, estimate pi = 3.1126
hits : 51391, trials: 80282, estimate pi = 3.1244
hits : 51698, trials: 80382, estimate pi = 3.1097
hits : 51780, trials: 80482, estimate pi = 3.1086
hits : 51823, trials: 80582, estimate pi = 3.1099
hits : 51701, trials: 80682, estimate pi = 3.1211
hits : 51740, trials: 80782, estimate pi = 3.1226
hits : 51925, trials: 80882, estimate pi = 3.1153
hits : 51821, trials: 80982, estimate pi = 3.1255
hits : 51911, trials: 81082, estimate pi = 3.1239
hits : 51818, trials: 81183, estimate pi = 3.1334
hits : 52259, trials: 81283, estimate pi = 3.1108
hits : 52132, trials: 81383, estimate pi = 3.1222
hits : 52170, trials: 81483, estimate pi = 3.1237
hits : 52418, trials: 81583, estimate pi = 3.1128
hits : 52265, trials: 81683, estimate pi = 3.1257
hits : 52728, trials: 81783, estimate pi = 3.1021
hits : 52570, trials: 81883, estimate pi = 3.1152
hits : 52625, trials: 81983, estimate pi = 3.1157
hits : 52621, trials: 82083, estimate pi = 3.1198
hits : 52355, trials: 82183, estimate pi = 3.1395
hits : 52712, trials: 82284, estimate pi = 3.1220
hits : 52861, trials: 82384, estimate pi = 3.1170
hits : 52732, trials: 82484, estimate pi = 3.1284
hits : 53299, trials: 82584, estimate pi = 3.0989
hits : 52984, trials: 82684, estimate pi = 3.1211
hits : 53192, trials: 82784, estimate pi = 3.1126
hits : 53071, trials: 82884, estimate pi = 3.1235
hits : 53215, trials: 82984, estimate pi = 3.1188
hits : 53344, trials: 83084, estimate pi = 3.1150
hits : 53317, trials: 83184, estimate pi = 3.1204
hits : 53476, trials: 83284, estimate pi = 3.1148
hits : 53706, trials: 83385, estimate pi = 3.1052
hits : 53795, trials: 83485, estimate pi = 3.1038
hits : 53606, trials: 83585, estimate pi = 3.1185
hits : 53731, trials: 83685, estimate pi = 3.1150
hits : 53709, trials: 83785, estimate pi = 3.1200
hits : 53874, trials: 83885, estimate pi = 3.1141
hits : 54054, trials: 83985, estimate pi = 3.1074
hits : 53925, trials: 84085, estimate pi = 3.1186
hits : 54181, trials: 84185, estimate pi = 3.1075
hits : 54104, trials: 84285, estimate pi = 3.1157
hits : 54530, trials: 84385, estimate pi = 3.0950
hits : 54413, trials: 84486, estimate pi = 3.1054
hits : 54173, trials: 84586, estimate pi = 3.1228
hits : 54558, trials: 84686, estimate pi = 3.1044
hits : 54383, trials: 84786, estimate pi = 3.1181
hits : 54398, trials: 84886, estimate pi = 3.1209
hits : 54666, trials: 84986, estimate pi = 3.1093
hits : 54544, trials: 85086, estimate pi = 3.1199
hits : 54816, trials: 85186, estimate pi = 3.1081
hits : 54483, trials: 85286, estimate pi = 3.1307
hits : 54551, trials: 85386, estimate pi = 3.1305
hits : 55068, trials: 85486, estimate pi = 3.1047
hits : 54833, trials: 85587, estimate pi = 3.1217
hits : 55141, trials: 85687, estimate pi = 3.1079
hits : 55133, trials: 85787, estimate pi = 3.1120
hits : 55274, trials: 85887, estimate pi = 3.1077
hits : 55361, trials: 85987, estimate pi = 3.1064
hits : 55233, trials: 86087, estimate pi = 3.1172
hits : 55415, trials: 86187, estimate pi = 3.1106
hits : 55285, trials: 86287, estimate pi = 3.1215
hits : 55495, trials: 86387, estimate pi = 3.1133
hits : 55599, trials: 86487, estimate pi = 3.1111
hits : 55698, trials: 86587, estimate pi = 3.1092
hits : 55849, trials: 86688, estimate pi = 3.1044
hits : 55573, trials: 86788, estimate pi = 3.1234
hits : 55678, trials: 86888, estimate pi = 3.1211
hits : 56055, trials: 86988, estimate pi = 3.1037
hits : 55871, trials: 87088, estimate pi = 3.1175
hits : 56070, trials: 87188, estimate pi = 3.1100
hits : 56118, trials: 87288, estimate pi = 3.1109
hits : 56242, trials: 87388, estimate pi = 3.1076
hits : 56298, trials: 87488, estimate pi = 3.1080
hits : 56340, trials: 87588, estimate pi = 3.1093
hits : 56129, trials: 87688, estimate pi = 3.1245
hits : 56501, trials: 87789, estimate pi = 3.1075
hits : 56379, trials: 87889, estimate pi = 3.1178
hits : 56296, trials: 87989, estimate pi = 3.1259
hits : 56653, trials: 88089, estimate pi = 3.1098
hits : 56588, trials: 88189, estimate pi = 3.1169
hits : 56444, trials: 88289, estimate pi = 3.1284
hits : 56730, trials: 88389, estimate pi = 3.1161
hits : 56751, trials: 88489, estimate pi = 3.1185
hits : 56925, trials: 88589, estimate pi = 3.1125
hits : 56970, trials: 88689, estimate pi = 3.1135
hits : 57053, trials: 88789, estimate pi = 3.1125
hits : 57262, trials: 88890, estimate pi = 3.1047
hits : 57049, trials: 88990, estimate pi = 3.1198
hits : 57325, trials: 89090, estimate pi = 3.1082
hits : 57386, trials: 89190, estimate pi = 3.1084
hits : 57592, trials: 89290, estimate pi = 3.1008
hits : 57267, trials: 89390, estimate pi = 3.1219
hits : 57555, trials: 89490, estimate pi = 3.1097
hits : 57541, trials: 89590, estimate pi = 3.1140
hits : 57640, trials: 89690, estimate pi = 3.1121
hits : 57794, trials: 89790, estimate pi = 3.1072
hits : 57703, trials: 89890, estimate pi = 3.1156
hits : 57868, trials: 89990, estimate pi = 3.1102
hits : 57838, trials: 90091, estimate pi = 3.1153
hits : 57688, trials: 90191, estimate pi = 3.1269
hits : 57923, trials: 90291, estimate pi = 3.1176
hits : 58096, trials: 90391, estimate pi = 3.1118
hits : 57988, trials: 90491, estimate pi = 3.1210
hits : 58210, trials: 90591, estimate pi = 3.1126
hits : 58041, trials: 90691, estimate pi = 3.1251
hits : 58247, trials: 90791, estimate pi = 3.1174
hits : 58283, trials: 90891, estimate pi = 3.1190
hits : 58358, trials: 90991, estimate pi = 3.1184
hits : 58510, trials: 91091, estimate pi = 3.1137
hits : 58634, trials: 91192, estimate pi = 3.1106
hits : 58825, trials: 91292, estimate pi = 3.1039
hits : 58657, trials: 91392, estimate pi = 3.1161
hits : 58595, trials: 91492, estimate pi = 3.1229
hits : 58992, trials: 91592, estimate pi = 3.1052
hits : 59135, trials: 91692, estimate pi = 3.1011
hits : 59212, trials: 91792, estimate pi = 3.1005
hits : 59147, trials: 91892, estimate pi = 3.1072
hits : 59159, trials: 91992, estimate pi = 3.1100
hits : 59164, trials: 92092, estimate pi = 3.1131
hits : 58919, trials: 92192, estimate pi = 3.1294
hits : 59236, trials: 92293, estimate pi = 3.1161
hits : 59497, trials: 92393, estimate pi = 3.1058
hits : 59350, trials: 92493, estimate pi = 3.1169
hits : 59162, trials: 92593, estimate pi = 3.1302
hits : 59515, trials: 92693, estimate pi = 3.1149
hits : 59682, trials: 92793, estimate pi = 3.1096
hits : 59648, trials: 92893, estimate pi = 3.1147
hits : 59595, trials: 92993, estimate pi = 3.1208
hits : 59815, trials: 93093, estimate pi = 3.1127
hits : 59642, trials: 93193, estimate pi = 3.1251
hits : 59798, trials: 93293, estimate pi = 3.1203
hits : 60054, trials: 93394, estimate pi = 3.1103
hits : 60206, trials: 93494, estimate pi = 3.1058
hits : 60022, trials: 93594, estimate pi = 3.1187
hits : 59887, trials: 93694, estimate pi = 3.1290
hits : 60165, trials: 93794, estimate pi = 3.1179
hits : 60131, trials: 93894, estimate pi = 3.1230
hits : 60357, trials: 93994, estimate pi = 3.1146
hits : 60383, trials: 94094, estimate pi = 3.1166
hits : 60536, trials: 94194, estimate pi = 3.1120
hits : 60630, trials: 94294, estimate pi = 3.1105
hits : 60582, trials: 94394, estimate pi = 3.1162
hits : 60362, trials: 94495, estimate pi = 3.1309
hits : 60615, trials: 94595, estimate pi = 3.1212
hits : 60759, trials: 94695, estimate pi = 3.1171
hits : 60774, trials: 94795, estimate pi = 3.1196
hits : 61029, trials: 94895, estimate pi = 3.1098
hits : 61127, trials: 94995, estimate pi = 3.1081
hits : 60842, trials: 95095, estimate pi = 3.1260
hits : 61160, trials: 95195, estimate pi = 3.1130
hits : 61155, trials: 95295, estimate pi = 3.1165
hits : 60988, trials: 95395, estimate pi = 3.1283
hits : 61552, trials: 95495, estimate pi = 3.1029
hits : 61392, trials: 95596, estimate pi = 3.1143
hits : 61533, trials: 95696, estimate pi = 3.1104
hits : 61601, trials: 95796, estimate pi = 3.1102
hits : 61773, trials: 95896, estimate pi = 3.1048
hits : 61620, trials: 95996, estimate pi = 3.1157
hits : 61715, trials: 96096, estimate pi = 3.1142
hits : 61653, trials: 96196, estimate pi = 3.1206
hits : 61754, trials: 96296, estimate pi = 3.1187
hits : 62085, trials: 96396, estimate pi = 3.1053
hits : 61749, trials: 96496, estimate pi = 3.1254
hits : 61998, trials: 96596, estimate pi = 3.1161
hits : 61976, trials: 96697, estimate pi = 3.1205
hits : 62147, trials: 96797, estimate pi = 3.1151
hits : 62124, trials: 96897, estimate pi = 3.1195
hits : 62164, trials: 96997, estimate pi = 3.1207
hits : 62536, trials: 97097, estimate pi = 3.1053
hits : 62197, trials: 97197, estimate pi = 3.1255
hits : 62695, trials: 97297, estimate pi = 3.1038
hits : 62275, trials: 97397, estimate pi = 3.1280
hits : 62653, trials: 97497, estimate pi = 3.1123
hits : 62805, trials: 97597, estimate pi = 3.1079
hits : 62770, trials: 97697, estimate pi = 3.1129
hits : 62734, trials: 97798, estimate pi = 3.1179
hits : 62966, trials: 97898, estimate pi = 3.1096
hits : 62845, trials: 97998, estimate pi = 3.1187
hits : 63099, trials: 98098, estimate pi = 3.1093
hits : 63018, trials: 98198, estimate pi = 3.1165
hits : 63058, trials: 98298, estimate pi = 3.1177
hits : 63190, trials: 98398, estimate pi = 3.1144
hits : 63260, trials: 98498, estimate pi = 3.1141
hits : 63374, trials: 98598, estimate pi = 3.1116
hits : 63413, trials: 98698, estimate pi = 3.1129
hits : 63239, trials: 98798, estimate pi = 3.1246
hits : 63784, trials: 98899, estimate pi = 3.1011
hits : 63666, trials: 98999, estimate pi = 3.1099
hits : 63825, trials: 99099, estimate pi = 3.1053
hits : 63678, trials: 99199, estimate pi = 3.1156
hits : 64064, trials: 99299, estimate pi = 3.1000
hits : 63926, trials: 99399, estimate pi = 3.1098
hits : 63675, trials: 99499, estimate pi = 3.1252
hits : 63871, trials: 99599, estimate pi = 3.1188
hits : 63876, trials: 99699, estimate pi = 3.1216
hits : 64093, trials: 99799, estimate pi = 3.1142
hits : 64066, trials: 99899, estimate pi = 3.1186
hits : 64286, trials: 100000, estimate pi = 3.1111

In [6]:
# plot graphs
plt.plot(trials, pi_list ,color='green')
plt.title("Estimating the value of pi via Buffon's Needle")
plt.xlabel('# of Needles')
plt.ylabel('Estimated value of pi')
plt.ylim(3.08,3.16)
plt.show()


In [8]:
plt.hist(pi_list, bins = np.linspace(3.08,3.16,50), color='green')
plt.title("Estimating the value of pi via Buffon's Needle")
plt.xlabel('Estimated value of pi')
plt.xlim(3.08,3.16)
plt.show()

In [ ]:
Generate Random Needles on a Plot

In [11]:
hits_ = 0
num_needles = 1000

#  define grid space
for vlines in range(-4,4):
plot_grid_lines(vlines)

vlines = range(-4,4)

for pin in xrange(num_needles):
origin, end = needle_construct_graph(mode = 'plot')
hits_ += collision_detection(origin, end, vlines)

# plot title
plt.title("Plotting randomly generated needles of length 1 on grid")

print 'hits', hits_
print 'drops', num_needles
print 'PI =', calculate_pi(hits_, num_needles)

hits 628
drops 1000
PI = 3.1847133758

In [ ]: