-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi.py
49 lines (39 loc) · 887 Bytes
/
pi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from math import *
import matplotlib.pyplot as plt
# OPEN
root_number = 'pi'
cifre = 10000000
quanti = 1000
file_name = str(root_number)+'.txt'
file = open(file_name, "rb").read()
def discalculator(initial, precision, x, y):
numeri = file[initial:precision]
index2 = 0
for val in numeri:
if index2 % 4 == 0:
x += int(val)
if index2 % 4 == 2:
x -= int(val)
if index2 % 4 == 1:
y += int(val)
if index2 % 4 == 3:
y -= int(val)
index2 += 1
distance = sqrt(x**2 + y**2)
return distance, x, y
# Loop + Graph
xes = []
yes = []
xval = 0
yval = 0
for i in range (1,quanti+1):
precision = (cifre/quanti)*i
initial = (cifre/quanti)*(i-1)
values = discalculator(initial, precision, xval, yval)
xes.append(precision)
yes.append(values[0])
print(precision, values[0])
xval = values[1]
yval = values[2]
plt.plot(xes, yes)
plt.show()