Skip to content

Instantly share code, notes, and snippets.

@mailpraveens
Created February 26, 2014 07:25
Show Gist options
  • Save mailpraveens/9225175 to your computer and use it in GitHub Desktop.
Save mailpraveens/9225175 to your computer and use it in GitHub Desktop.
Test to verify the theorem for squaring numbers greater than 25 found on Quora. For fun.
#http://www.quora.com/Whats-a-math-trick-that-is-not-very-well-known/answers/4234574
import sys
def verifySquaringTheorem(n):
for i in range(25,n):
nSquaredSupposed = (( i - 25 ) * 100) + pow(i-50,2)
actualSquare = pow(i,2);
if nSquaredSupposed == actualSquare:
print ("Pass for n = " + str(i) + " with value " + str(nSquaredSupposed))
else:
print("Fail for n = " + str(i) + "with value " + str(nSquaredSupposed) + "and actualSquare value = " + str(actualSquare))
return
def main():
verifySquaringTheorem(1000)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment