Skip to content

Instantly share code, notes, and snippets.

@ameerkat
Created April 5, 2011 04:09
Show Gist options
  • Save ameerkat/903007 to your computer and use it in GitHub Desktop.
Save ameerkat/903007 to your computer and use it in GitHub Desktop.
Project euler #39, attempt 3 using some facts about the parity of a and b
from fractions import gcd
def euler39better2():
sum_count = [0] * 1001
triples_to_check = []
for a in range(2000/3):
if a%100 == 0:
print "|",
for b in range((a%2)+1, a+1, 2):
for c in range(a+1,1001-a-b):
if a**2 + b**2 == c**2:
if gcd(a, b) == 1 and gcd(a, c) == 1 and gcd(b, c) == 1:
for i in range(1, 1000/(a+b+c) + 1):
sum_count[a*i + b*i + c*i] += 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