Created
April 5, 2011 04:28
-
-
Save ameerkat/903035 to your computer and use it in GitHub Desktop.
Fully optimized euler #39!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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