Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created March 15, 2012 09:55
Show Gist options
  • Save shieldsd/2043385 to your computer and use it in GitHub Desktop.
Save shieldsd/2043385 to your computer and use it in GitHub Desktop.
Project Euler #9
from itertools import count
from itertools import dropwhile
from math import sqrt
from operator import mul
def triple():
for a in range(1, 1000):
for b in range(a + 1, 1000):
c = int(sqrt(a * a + b * b))
if c * c == a * a + b * b:
yield (a, b, c)
print reduce(mul,
dropwhile(lambda (a, b, c): a + b + c != 1000,
triple()).next())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment