Skip to content

Instantly share code, notes, and snippets.

@justinmeiners
Last active June 10, 2019 18:16
Show Gist options
  • Save justinmeiners/b050fdfb387fd7be1b6fa84f070400fe to your computer and use it in GitHub Desktop.
Save justinmeiners/b050fdfb387fd7be1b6fa84f070400fe to your computer and use it in GitHub Desktop.
I explained to a friend how sqrt can be implemented.
import math
def sqrt(x_0, guess, tol):
x = guess
while math.fabs(x*x - x_0) > tol:
x = (x*x - x_0) / (2.0 * x)
return x
print(sqrt(2.0, 2.0, 0.0001))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment