← Projects

don't understand how this works but it works

f31aa24539aa84bbc7596bfe2098b51535f51132 · ovidiucs · May 10, 2015 19:52

+25 −1 · 1 file changed

  • 01-Find-PI-to-Nth-Digit.py +25 −1
diff --git a/01-Find-PI-to-Nth-Digit.py b/01-Find-PI-to-Nth-Digit.py
index dd46eed..fd7238b 100644
--- a/01-Find-PI-to-Nth-Digit.py
+++ b/01-Find-PI-to-Nth-Digit.py
@@ -1 +1,25 @@
-__author__ = 'ovidiucs'
+__author__ = 'notme'
+
+
+def make_pi():
+    q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
+    for j in range(1000):
+        if 4 * q + r - t < m * t:
+            yield m
+            q, r, t, k, m, x = 10 * q, 10 * (r - m * t), t, k, (
+            10 * (3 * q + r)) // t - 10 * m, x
+        else:
+            q, r, t, k, m, x = q * k, (2 * q + r) * x, t * x, k + 1, (
+            q * (7 * k + 2) + r * x) // (t * x), x + 2
+
+
+digits = make_pi()
+pi_list = []
+my_array = []
+
+for i in make_pi():
+    my_array.append(str(i))
+
+my_array = my_array[:1] + ['.'] + my_array[1:]
+big_string = "".join(my_array)
+print "here is a big string:\n %s" % big_string
\ No newline at end of file