Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,14 @@
import math
proc agm(a, g: float,delta: float = 1.0e-15): float =
var
aNew: float = 0
aOld: float = a
gOld: float = g
while (abs(aOld - gOld) > delta):
aNew = 0.5 * (aOld + gOld)
gOld = sqrt(aOld * gOld)
aOld = aNew
result = aOld
echo ($agm(1.0,1.0/sqrt(2)))

View file

@ -0,0 +1,20 @@
from math import sqrt
from strutils import parseFloat, formatFloat, ffDecimal
proc agm(x,y: float): tuple[resA,resG: float] =
var
a,g: array[0 .. 23,float]
a[0] = x
g[0] = y
for n in 1 .. 23:
a[n] = 0.5 * (a[n - 1] + g[n - 1])
g[n] = sqrt(a[n - 1] * g[n - 1])
(a[23], g[23])
var t = agm(1, 1/sqrt(2))
echo("Result A: " & formatFloat(t.resA, ffDecimal, 24))
echo("Result G: " & formatFloat(t.resG, ffDecimal, 24))