Esempio n. 1
0
import brandonsEP
import math

primes = brandonsEP.sieve(10**6)
oneDPrimes = [2,3,5,7]
del primes[:4]

primesofDigit = [[]] * 7
primesofDigit[1] = oneDPrimes

digits = 1
beginIndex = 0
for i in range(len(primes)):
    if int(math.log10(primes[i]))>digits:
        digits +=1
        primesofDigit[digits] = primes[beginIndex:i]
        beginIndex = i
primesofDigit[digits+1] = primes[beginIndex:]

reducedPrimes = primes[:]

def valid(num, digits): 
    rightTrunc = False
    leftTrunc = num%(10**digits) in primesofDigit[digits] 
    if leftTrunc: 
        rightTrunc = num//10**(int(math.log10(num))-digits+1) in primesofDigit[digits]
    return rightTrunc and leftTrunc

winers = []
for x in range(1,6):
    reducedPrimes = [p for p in reducedPrimes if valid(p,x)]
Esempio n. 2
0
import brandonsEP
import itertools

p = brandonsEP.sieve(100)
bsi = brandonsEP.binary_search_index

def pslice(min, max):
    return p[bsi(p,min):bsi(p,max)+1]

def addto(n, min = 1):
    if n<=0: return not n

    total = 0
    for part in pslice(min,n):
        total += addto(n-part, min=part)
    return total

for n in itertools.count(start=11):
    if addto(n)>5000:
        print n
        break
Esempio n. 3
0
         [3373, 3631, 8923, 14083], [2687, 3023, 8069, 14447],
         [11527, 12073, 12703, 14737], [4201, 4759, 14797, 16729],
         [6323, 6491, 8237, 17333], [659, 947, 5009, 18233],
         [5209, 5419, 9241, 18427], [6047, 6203, 7643, 19727],
         [373, 661, 1237, 20011], [15359, 15737, 18401, 20333]]
fours.sort(key=sum)

isP = brandonsEP.isPrime
cc = brandonsEP.concatNums


def doubleCC(a, b):
    return isP(cc(a, b)) and isP(cc(b, a))


p = brandonsEP.sieve(10**6)


def search(four):
    print four
    for a in p:
        #if all(doubleCC(a,b) for a,b in combinations(four+[num],2)):
        #    print num, sum(four)+num
        for b in four:
            if not doubleCC(a, b): break
        else:
            print a, sum(four) + a


search([5197, 5701, 6733, 8389])
#for x in fours: search(x)
import math, brandonsEP
from collections import defaultdict
import itertools


def nlen(x):
    return int(math.log10(x)) + 1


fourDPs = brandonsEP.sieve(10**4)

fourDPs = [x for x in fourDPs if nlen(x) == 4]

print len(fourDPs)

sets = defaultdict(list)

for p in fourDPs:
    l = sets[brandonsEP.lsToNum(sorted(brandonsEP.digits(p), reverse=True))]
    l.append(p)

#{brandonsEP.lsToNum(sorted(brandonsEP.digits(d), reverse=True)):d for d in fourDPs}

for k, v in sets.items():
    if len(v) < 3: del sets[k]

#print sets, len(sets)


def search(Ps):
    for num in Ps:
Esempio n. 5
0
from brandonsEP import sieve

import timeit
timein = timeit.time.time()

LIMIT = 10**6

primes = sieve(LIMIT)
pset = set(primes)


#0.264675140381 seconds
def search1(sliceSize):
    #search from 0-s to n-s to n
    for i in range(len(primes) - sliceSize + 1):
        s = sum(primes[i:i + sliceSize])
        if s > primes[-1]: return None
        if s in pset: return s
    return None


# 0.128955125809  seconds
def search2(sliceSize):
    s = sum(primes[:sliceSize])
    for i in range(len(primes) - sliceSize + 1):
        if s > primes[-1]: return None
        if s in pset: return s

        s = s - primes[i] + primes[i + sliceSize]

    return None