Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 6, 2011 19:45
Show Gist options
  • Select an option

  • Save jakedobkin/1439641 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1439641 to your computer and use it in GitHub Desktop.
Euler 39 Python
# initialize an array to hold results
l=[0]*1001
# brute force to calculate a,b,c
for a in range(1,1000):
for b in range(1,1000):
c = (a**2 + b**2)**0.5
# verify c is a perfect square and p is < 1000, if it is, increment count
if (a+b+c<=1000 and c-round(c,0)==0):
p = int(a + b + c);
l[p]+=1;
# print the largest p with the number of combos
max = 0
for i in range (1,1000):
if l[i] > max:
max = l[i]
max_p = i
print max_p, max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment