Created
December 6, 2011 19:45
-
-
Save jakedobkin/1439641 to your computer and use it in GitHub Desktop.
Euler 39 Python
This file contains hidden or 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
| # 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