rac_precise.py

Created by schraf

Created on April 06, 2020

703 Bytes

Calculer plusieurs milliers de décimales exactes des racines carrées avec cet algorithme.

Explications en vidéo ici


# exemple racine de 2

def rac(a = 2):
  b, m, k = 0, 0, 0
  while True:
    if k > 0: a = 100 * (a - b)
    k += 1
    s = 9
    while (20 * m + s) * s > a: s -= 1
    b = (20 * m + s) * s
    m = 10 * m + s
    print(s, end="")
    if k%25 == 0: print()
    if k%250 == 0: 
      print(">>",k)
      input()  

# exemple racine de 1234567890 
      
def rac2():
  n = [12,34,56,78,90]
  a, b, m, k = 0, 0, 0, 0
  while True:
    a = 100 * (a - b)
    if k < len(n): a += n[k] 
    k += 1
    s = 9
    while (20 * m + s) * s > a: s -= 1
    b = (20 * m + s) * s
    m = 10 * m + s
    print(s, end="")
    if k%25 == 0: print()
    if k%250 == 0: 
      print(">>",k)
      input()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.