Skip to content

Instantly share code, notes, and snippets.

@therealbill
Created June 18, 2012 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therealbill/2946996 to your computer and use it in GitHub Desktop.
Save therealbill/2946996 to your computer and use it in GitHub Desktop.
triplets
#!/usr/bin/env python
import timeit
from random import choice
def getTriplets(top=1000):
triplets = []
for c in xrange(top,3,-1):
maxb = top-c - 1
for b in xrange(maxb,0,-1):
a = top -c -b
if (a**2 +b**2) == (c**2):
#print (a,b,c)
return [ (a,b,c) ]
from timeit import Timer
t = Timer("getTriplets()", "from __main__ import getTriplets")
print "%.2f usec/pass on %d runs" % ( (100 * t.timeit(number=100)/100), 100 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment