Created
December 9, 2011 20:21
-
-
Save jakedobkin/1453136 to your computer and use it in GitHub Desktop.
Euler 46 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
| # set up prime seive | |
| n=10000 | |
| myPrimes = [] | |
| myPrimes = [True]*10001 | |
| myPrimes[0] = False | |
| myPrimes[1] = False | |
| for i in range (2,n): | |
| if myPrimes[i] == True: | |
| j = 2*i | |
| while j<=n: | |
| myPrimes[j]=False | |
| j=j+i | |
| # set up set of squares | |
| s = set() | |
| for k in range (0,100): | |
| s.add(2*k*k) | |
| # start searching up- test all odd non-prime numbers | |
| i = 33 | |
| found = False | |
| while found == False: | |
| if myPrimes[i] == False: | |
| for l in range (0,len(myPrimes)-1): | |
| if myPrimes[l]==True: | |
| found = True | |
| test = i - l | |
| if test in s: | |
| found = False | |
| break | |
| if found == True: | |
| print "Answer:", i | |
| i = i+2 | |
Author
jakedobkin
commented
Dec 9, 2011
via email
i figured that out without asking djacobs!
Jake Dobkin
Gothamist.com
(p) 917 627 6915
(f) 646 349 3893
AIM, YIM, GTalk: jakedobkin
Mediakit: www.gothamistllc.com
…On Fri, Dec 9, 2011 at 5:19 PM, nataliepo < ***@***.*** > wrote:
i am impressed with the array allocation syntax on line 4, jake!
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1453136
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment