Add all the A tasks

This commit is contained in:
Ingy döt Net 2013-04-10 14:58:50 -07:00
parent 2dd7375f96
commit 051504d65b
1608 changed files with 18584 additions and 0 deletions

View file

@ -0,0 +1,16 @@
from math import sqrt
def agm(a0, g0, tolerance=1e-10):
"""
Calculating the arithmetic-geometric mean of two numbers a0, g0.
tolerance the tolerance for the converged
value of the arithmetic-geometric mean
(default value = 1e-10)
"""
[an, gn] = [(a0 + g0) / 2.0, sqrt(a0 * g0)]
while abs(an - gn) > tolerance:
[an, gn] = [(an + gn) / 2.0, sqrt(an * gn)]
return an
print agm(1, 1 / sqrt(2))

View file

@ -0,0 +1,10 @@
from decimal import Decimal, getcontext
def agm(a, g, tolerance=Decimal("1e-65")):
while True:
a, g = ((a + g) / 2, (a * g).sqrt())
if abs(a - g) < tolerance:
return a
getcontext().prec = 70
print agm(Decimal(1), 1 / Decimal(2).sqrt())