Skip to content

Instantly share code, notes, and snippets.

@ameerkat
Created April 5, 2011 04:28
Show Gist options
  • Save ameerkat/903035 to your computer and use it in GitHub Desktop.
Save ameerkat/903035 to your computer and use it in GitHub Desktop.
Fully optimized euler #39!
from fractions import gcd
def euler39optimized():
sum_count = [0] * 1001
y = 2
while y**2 <= 500:
for z in [x for x in range(y) if gcd(y, x) == 1]:
a = y**2 - z**2
b = 2*y*z
c = y**2 + z**2
for i in range(1, 1001/(a+b+c) + 1):
sum_count[a*i + b*i + c*i] += 1
y += 1
return sum_count.index(max(sum_count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment