示例#1
0
def replace(diglist, places, verbose=False):
    found = 0
    originalDigit = diglist[places[0]]
    for d in range(10):
        for i in places: diglist[i]=d
        if (  brandonsEP.binary_search(primes, brandonsEP.lsToNum(diglist))
          and diglist[0]):
            found+=1
            if verbose: print found, ":",brandonsEP.lsToNum(diglist)

    for i in places: diglist[i]=originalDigit
    return found
def replace(diglist, a, b):
    found = 0
    mutate = diglist[:]
    for i in range(10):
        mutate[a],mutate[b] = i,i
        if brandonsEP.binary_search(primes, brandonsEP.lsToNum(mutate)):
            found+=1
    return found
示例#3
0
def isLychrel(num):
    for iteration in xrange(1,50):
        dlist = brandonsEP.digits(num)
        rd = list(reversed(dlist))
        if dlist == rd and iteration!=1:
            return False
        num = num + brandonsEP.lsToNum(rd)
        #print dlist, rd, rd == dlist, num + brandonsEP.lsToNum(rd)
    else:
        return True
def findB(primesIndex,currentnum,numsremaining,result):
    if primes[primesIndex] == 2:
        if not currentnum[1]&1:
            result.append(numsremaining+currentnum)
            numsremaining.reverse()
            result.append(numsremaining+currentnum)
        return

    for n in numsremaining:
        if not lsToNum([n]+currentnum[:2])%primes[primesIndex]:
            findB(primesIndex+1, [n]+currentnum, [x for x in numsremaining if x != n], result)
示例#5
0
def search(perms):
    found = []
    nextp = perms.next()
    while nextp:
        nextp = list(nextp)
        num = lsToNum(nextp)
        if isPrime(num):
            print num
            return True
        nextp = next(perms, None)
    return False
def search(beg, end):
    global largest
    for i in range(beg, end):
        mult = 1
        concat = []
        while len(concat) < 9:
            concat.extend(digits(i * mult))
            mult += 1
        check = sorted(concat)
        if check == panDig:
            print concat, i
            num = lsToNum(concat)
            if num > largest: largest = num
import brandonsEP, collections


def pow3():
    n = 1
    while True:
        yield n**3
        n += 1


numlength = 0
perms = collections.defaultdict(list)

for x in pow3():
    if brandonsEP.lengthNum(x) > numlength:
        #print filter(lambda x:len(x)>2, perms.values())
        for ls in perms.values():
            if len(ls) == 5:
                print min(ls)
                exit()
        numlength = brandonsEP.lengthNum(x)
        perms.clear()
    k = brandonsEP.lsToNum(sorted(brandonsEP.digits(x)))
    perms[k].append(x)


pandigitals = []
for x in xrange(17,1000,17):
    dig = digits(x)
    if len(dig)<3: dig.insert(0, 0)
    a,b,c = dig[0],dig[1],dig[2]
    if a != b != c !=a:
        findB(1, dig, [x for x in range(10) if x not in dig], pandigitals)

#print factcors[primes[1]]
#test = (2,8)
#print "filtered", [x for x in factcors[primes[1]] if x[1:]==test]
#findB(1, [2,8,9], [x for x in range(10) if x not in [2,8,9]], pandigitals)

print pandigitals
print [1,4,0,6,3,5,7,2,8,9] in pandigitals
print len(pandigitals)
a= [lsToNum(x) for x in pandigitals]

b = [1430952867 ,  1460357289 ,  1406357289 , 4130952867 , 4160357289 , 4106357289]

print [x for x in a if x not in b]

print "sum=",sum(a)
#for p in primes: 
#recursive function needed here


###GETS THE WRONG ANSWER!!!
def wholeDeal(iter, x):
    return brandonsEP.lsToNum(sorted(toParts(iter, x)))

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:
        diffs = []
        for num2 in Ps:
            dif = abs(num - num2)