import prime import search primes = prime.primesTo(500) answers = [[-1]*501 for x in xrange(501)] def expand(min, sum): if answers[min][sum] != -1: return answers[min][sum] if min > sum: answers[min][sum] = 0 return 0 if search.searchList(primes,sum): totals = 1 else: totals = 0 for i in xrange((sum-min)/2 + 1): if search.searchList(primes,min+i): totals += expand(min + i, sum - (min + i)) answers[min][sum] = totals return totals # solves for the answer i = 0 temp = expand(2,i) while temp < 5000: i += 1 temp = expand(2,i) print i
import prime import search import string import itertools primes = prime.primesTo(10000) # returns True if concatinating the two numbers in any order results in a prime def ccatPrimes(a,b): return prime.isPrime(int(str(a)+str(b))) and prime.isPrime(int(str(b)+str(a))) def findAnswer(): minSum = 100000 for a in primes: for b in primes: if a+b < minSum and ccatPrimes(a,b): for c in primes: if a+b+c < minSum and ccatPrimes(a,c) and ccatPrimes(b,c): for d in primes: if a+b+c+d < minSum and ccatPrimes(a,d) and ccatPrimes(b,d) and ccatPrimes(c,d): print str(a)+","+str(b)+","+str(c)+","+str(d) for e in primes: if a+b+c+d+e < minSum and ccatPrimes(a,e) and ccatPrimes(b,e) and ccatPrimes(c,e) and ccatPrimes(d,e): minSum = a+b+c+d+e print str(a)+","+str(b)+","+str(c)+","+str(d)+","+str(e)+" - "+str(minSum) return minSum def findAnswer2(): combs = {} for a in primes: combs[a] = []
#modules and packages import prime as pr #importing function from a module from prime import primesTo #print(dir(pr)) #pr.primesTo(100) primesTo(100)