In [1]:
from euler import make_square_roots
In [2]:
make_square_roots(10)
Out[2]:
In [3]:
def foo(n):
square_roots = dict(make_square_roots(n))
for a in xrange(1, n / 2):
for b in xrange(a + 1, n / 2):
c_squared = a*a + b*b
try:
c = square_roots[c_squared]
except KeyError:
continue
if a + b + c == n:
yield a, b, c
In [4]:
%timeit list(foo(1000))
list(foo(1000))
Out[4]: