Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 9, 2011 20:21
Show Gist options
  • Select an option

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

Select an option

Save jakedobkin/1453136 to your computer and use it in GitHub Desktop.
Euler 46 Python
# 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
@nataliepo
Copy link

i am impressed with the array allocation syntax on line 4, jake!

@jakedobkin
Copy link
Author

jakedobkin commented Dec 9, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment