Skip to content

Instantly share code, notes, and snippets.

@daedalus
Last active August 29, 2015 14:23
Show Gist options
  • Save daedalus/ed4a833abf27741445b8 to your computer and use it in GitHub Desktop.
Save daedalus/ed4a833abf27741445b8 to your computer and use it in GitHub Desktop.
sqrt2aprox
# given the x**2-2=0 condition we bruteforce an aproximation to sqrt(2)
def sqrt2test():
x = 2
error = 1
step = 0.5
lower_error = 1
i = 0
while (error != 0):
i = i + 1
error = (x**2-2)
x = x - (error * step)
if error < lower_error:
lower_error = error
print "Count: %d, Aprox: %s, Error: %s, LowerError: %s" % (i,x,error,lower_error)
sqrt2test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment