#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Arithmetic-geometric_mean
#

func agm(a, g) {
    loop {
        var x = [(a+g) / 2, sqrt(a*g)];
        x == [a, g] && return a;
        (a, g) = x...;
    }
}
 
say agm(1, 1/sqrt(2));
