Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 10, 2011 19:35
Show Gist options
  • Select an option

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

Select an option

Save jakedobkin/1456068 to your computer and use it in GitHub Desktop.
Euler 49 Prime Permutations
# http://projecteuler.net/problem=49
# we'll use the python built-in permutation function
import itertools
# prime sieve
n=100000
myPrimes = [True]*(n+1)
for i in range (2,n):
if myPrimes[i] == True:
j = 2*i
while j<=n:
myPrimes[j]=False
j=j+i
# for each k, see if b and c are in the set of prime permutations
for k in range (1488,9999):
if myPrimes[k] == True:
b = k + 3330
c = k + 6660
perms = itertools.permutations(str(k), 4)
my_set = set()
for l in perms:
number=int("".join(list(l)))
if number>1000 and myPrimes[number]:
my_set.add(number)
if b in my_set and c in my_set:
print "set is",k,b,c
print "string is",str(k)+str(b)+str(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment