コード例 #1
0
def search():
    for p in primes[primes.index(101):]:
        dig = brandonsEP.digits(p)
        for a,b in itertools.combinations(range(len(dig)), 2):
            if dig[a]==dig[b]:
              score = replace(dig, a, b)
              #print score
              #print a,b, p, score,  dig[a],dig[b], dig
              if score==8: return p
コード例 #2
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
コード例 #3
0
def search():
    for p in primes[primes.index(101):]:
        dig = brandonsEP.digits(p)
        for length in range(2,len(dig)):
          for combo in itertools.combinations(range(len(dig)), length):
              if all(dig[x]==dig[combo[0]] for x in combo):
                score = replace(dig, combo)
                #print score
                #print a,b, p, score,  dig[a],dig[b], dig
                if score==8: 
                  replace(dig, combo, verbose=True)
                  return p
コード例 #4
0
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
コード例 #5
0
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)
コード例 #6
0
from brandonsEP import digits
from brandonsEP import lsToNum

primes = [17,13,11,7,5,3,2]

factcors = {}

for p in primes:
    #factcors[p]=[tuple(digits(i*p)) for i in xrange(100//p+1,1000//p)]
    #factcors[p]=[(a,b,c) for a,b,c in factcors[p] if a!=b and b!=c and a!=c]
    total = p
    factcors[p] = []
    while total<1000:
        num = digits(total)
        if total<100: num.insert(0, 0)
        if total>9 and num[0] != num[1] != num[2] != num[0]:
            factcors[p].append(tuple(num))
        total+=p


def findPD(primesIndex,currentnum,numsremaining,result):
    if primes[primesIndex] == 2:
        result.append(numsremaining+currentnum)
        numsremaining.reverse()
        result.append(numsremaining+currentnum)
        return

    #print "nums remaing:", numsremaining, " currentnum:", currentnum

    ##print currentnum, currentnum[:2], factcors[primes[primesIndex]][3][1:]
    test = tuple(currentnum[:2])
コード例 #7
0
def sumfact(num):
    return sum(map(lambda x: facts[x], brandonsEP.digits(num)))
コード例 #8
0
import brandonsEP

i = 0
while  True:
	i+=1
	ds = sorted(brandonsEP.digits(i))
	for x in range(2,7):
		if sorted(brandonsEP.digits(i*x)) != ds:
			break
	else:
		print i
		for x in range(2,7): print i*x,
		break

コード例 #9
0
def sumfact(num):
    return sum(map(factorial, brandonsEP.digits(num)))
コード例 #10
0

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)
コード例 #11
0
import brandonsEP

digsums = []

for a in range(1, 100):
    for b in range(1, 100):
        digsums.append(sum(brandonsEP.digits(a**b)))
print max(digsums)
コード例 #12
0
def rotations(num):
    digs = brandonsEP.digits(num)
    result = [digs[x:] + digs[:x] for x in range(len(digs))]
    return [toNum(x) for x in result]
コード例 #13
0
from brandonsEP import digits


def isPalindrome(num):
    num = str(num)
    return num == num[::-1]


#binary test isPalindrome(bin(x)[2:])

sumb = 0
for i in range(1, 1000):
    podd = i
    peven = i
    digs = digits(i, reverse=True)
    for i in range(len(digs)):
        peven *= 10
        peven += digs[i]
        if i:
            podd *= 10
            podd += digs[i]
    if isPalindrome(bin(podd)[2:]): sumb += podd
    if isPalindrome(bin(peven)[2:]): sumb += peven

print sumb