Skip to content

Instantly share code, notes, and snippets.

@johnotu
Created September 28, 2016 19:15
Show Gist options
  • Select an option

  • Save johnotu/2ac1528bf1e5414aa7cc7085b3e44c97 to your computer and use it in GitHub Desktop.

Select an option

Save johnotu/2ac1528bf1e5414aa7cc7085b3e44c97 to your computer and use it in GitHub Desktop.
def square_root (n,d)
g1 = (n* 1.0) / 2
g2 = (g1 + (n /g1)) /2
while (g1 - g2).abs >= d
g1 = g2
g2 = (g1 + (n / g1)) / 2
end
g2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment