Exemplo n.º 1
0
def p37():
    b = True
    count = 0
    total = 0
    for i in range(10, 1000000):
        if pelib.isprime(i):
            b = True
            #print
            #print i
            for j in range(0, len(str(i))):
                if pelib.isprime(int(str(i)[j:])) and pelib.isprime(
                        int(str(i)[:j + 1])):
                    #print str(i)[j:], str(i)[:j+1]
                    pass
                else:
                    b = False
                    #print "failed"
            if b:
                count += 1
                total += i
                #print
                print count, i, total
                #for j in range(0,len(str(i))):
                #    print str(i)[j:], str(i)[:j+1]
    return total
Exemplo n.º 2
0
def p41(n):
    lexpos = [0]*n
    for i in xrange(math.factorial(n)):
        lexpos = incr_lexpos(lexpos, n)
        if pelib.isprime(list_to_num(lexpos_to_num(lexpos, n))):
            print list_to_num(lexpos_to_num(lexpos, n))
    return
Exemplo n.º 3
0
def p51():
	num = 0
	while True:
		num += 1
		if not pelib.isprime(num):
			continue

		for i in range(3):
			strnum = str(num)
			if strnum.count(str(i)) == 0:
				continue
			tally = 1
			for j in range(i+1, 10):
				replaced = int(strnum.replace(str(i), str(j))) 
				if pelib.isprime(replaced):
					tally += 1
			if tally == 8:
				return num
Exemplo n.º 4
0
def p51():
    num = 0
    while True:
        num += 1
        if num % 1000 == 0:
            print num
        if pelib.isprime(num):

            for i in range(3): #i may be doing some repetative calculations here
                #hopefully it won't be much
                has = has012(num, str(i))
                if has != False:
                    tally = 1
                    for j in range(i+1, 10):
                        if pelib.isprime(perm(num, str(i), str(j))):
                            tally += 1
                    if tally == 8:
                        print "found it!!!" , num
                        print "found the smallest prime in a eight prime value family"
                        return num
                    if tally == 7 and i > 0:
                        print "potential alternative condition", num
Exemplo n.º 5
0
def p51():
    num = 0
    while True:
        num += 1
        if num % 1000 == 0:
            print num
        if pelib.isprime(num):

            for i in range(
                    3):  #i may be doing some repetative calculations here
                #hopefully it won't be much
                has = has012(num, str(i))
                if has != False:
                    tally = 1
                    for j in range(i + 1, 10):
                        if pelib.isprime(perm(num, str(i), str(j))):
                            tally += 1
                    if tally == 8:
                        print "found it!!!", num
                        print "found the smallest prime in a eight prime value family"
                        return num
                    if tally == 7 and i > 0:
                        print "potential alternative condition", num
Exemplo n.º 6
0
def p37():
    b = True
    count = 0
    total = 0
    for i in range(10,1000000):
        if pelib.isprime(i):
            b = True
            #print
            #print i
            for j in range(0,len(str(i))):
                if pelib.isprime(int(str(i)[j:])) and pelib.isprime(int(str(i)[:j+1])):
                    #print str(i)[j:], str(i)[:j+1]
                    pass
                else:
                    b = False
                    #print "failed"
            if b:
                count += 1
                total += i
                #print
                print count, i, total
                #for j in range(0,len(str(i))):
                #    print str(i)[j:], str(i)[:j+1]
    return total