Distributed and decentralized pi calculation

greg

+29 -11
+29 -11
src/client/client.py
··· 1 1 from math import factorial 2 2 from decimal import Decimal, getcontext 3 + import time 4 + import threading 5 + 3 6 print("Pistributed, an app to calculate Pi with distributed power.") 4 7 print("Do not run on systems owned by another entity, entities, person, or people, without explicit permission from them.") 5 8 print("""This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ··· 8 11 9 12 You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.""") 10 13 print("By continuing, you agree to these terms, disclaimers, and acknowledge that there is NO WARRANTY.") 11 - input("I agree, and would like to continue. (to continue, press enter)") 14 + input("I agree, and would like to continue. (to continue, press enter) ") 12 15 print("Thanks for confirming! I just need one more thing.") 13 16 server = input("What is the server URL that you'd like to connect to? (ex: example.com) ") 14 17 print("Alright! Thanks. Let the calculating begin :D (to exit, run ctrl+c or close terminal)") 15 18 print("-------------------") 16 - getcontext().prec=100 17 - def calc(n): 18 - t= Decimal(0) 19 + 20 + def calc(n, prec): 21 + getcontext().prec = prec 22 + t = Decimal(0) 19 23 pi = Decimal(0) 20 - deno= Decimal(0) 21 - k = 0 24 + deno = Decimal(0) 22 25 for k in range(n): 23 - t = ((-1)**k)*(factorial(6*k))*(13591409+545140134*k) 24 - deno = factorial(3*k)*(factorial(k)**3)*(640320**(3*k)) 25 - pi += Decimal(t)/Decimal(deno) 26 - pi = pi * Decimal(12)/Decimal(640320**Decimal(1.5)) 26 + t = ((-1)**k) * (factorial(6*k)) * (13591409 + 545140134*k) 27 + deno = factorial(3*k) * (factorial(k)**3) * (640320**(3*k)) 28 + pi += Decimal(t) / Decimal(deno) 29 + pi = pi * Decimal(12) / Decimal(640320**Decimal(1.5)) 27 30 pi = 1/pi 28 31 return pi 29 - print(calc(100)) 32 + 33 + def upload(): 34 + while True: 35 + print(">> uploading latest calculation") 36 + time.sleep(60) 37 + 38 + threading.Thread(target=upload, daemon=True).start() 39 + 40 + calculation = 1 41 + precision = 10 42 + 43 + while True: 44 + pi_val = calc(calculation, precision) 45 + print(pi_val) 46 + calculation += 1 47 + precision += 5