document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #! /usr/bin/python
  2.  
  3. import sys
  4. import math
  5.  
  6. x=float(sys.argv[1])
  7. guess=42    # I want a +ve root, so seed is +ve
  8.  
  9. i=0
  10. while guess*guess!=x and i<20:
  11. # The iteration check is a must as many of the square-roots
  12. # are irrational. The algorithm is quadratically convergent.
  13. # ie. number of correct digits of the approximation doubles
  14. # with each iteration. So a limit of 20 is pretty good.
  15.     guess = (guess+x/guess)/2
  16.     i+=1
  17.     # print \'guess=%f\\titer=%d\' % (guess,i)
  18.  
  19. print guess
');