In [1]:
from euler import make_square_roots
In [2]:
make_square_roots(10)
Out[2]:
In [3]:
dict(make_square_roots(10))
Out[3]:
In [4]:
def foo(n):
square_roots = dict(make_square_roots(n))
for a in xrange(1, n / 2 + 1):
for b in xrange(a + 1, n / 2 + 1):
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 [5]:
%timeit list(foo(1000))
list(foo(1000))
Out[5]: