def primePermute(num): permute=[int(''.join(i)) for i in list(permutations(str(num)))] answer=[] for i in permute: if i not in answer and isprime(i) and i>1000: answer.append(i) return sorted(answer)
def checkFamily(fixedRoot, insertions, digits): family = [] insert = 0 for i in range(len(insertions)): if insertions[i] == 1: insert += 10**i fixedRoot += 9 * 10**i * int(fixedRoot / (10**i)) for n in range(10): family.append(fixedRoot + insert * n) familyPrimes = [i for i in family if isprime(i) and i > 10**(digits - 1)] if len(familyPrimes) >= 8: return min(familyPrimes) return 0
def largestPandigitPrime(): primes = [] for n in range(9, 0, -1): pandigits = list(permutations([i for i in range(1, n + 1)])) pandigits = [ int(''.join([str(j) for j in pandigits[i]])) for i in range(len(pandigits)) ] for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]: pandigits = [i for i in pandigits if i % p != 0] pandigits.sort(reverse=True) for i in range(len(pandigits)): if isprime(pandigits[i]): return pandigits[i] return 0
def Problem_35(): def number_rotator(number): number = deque(number) number.rotate(-1) return(''.join(number)) list_of_normal_primes, circular_primes = list_substractor(sieveErato(1000000), sieveErato(10)), {2,3,5,7} for normal_prime in list_of_normal_primes: check_num, circular_prime_checker = str(normal_prime), 0 for x in range(len(check_num)-1): check_num = number_rotator(check_num) if isprime(int(check_num)): circular_prime_checker += 1 continue break if circular_prime_checker == len(str(normal_prime))-1: circular_primes.add(normal_prime) print(len(circular_primes))
from itertools import permutations from myFunctions import isprime def primePermute(num): permute=[int(''.join(i)) for i in list(permutations(str(num)))] answer=[] for i in permute: if i not in answer and isprime(i) and i>1000: answer.append(i) return sorted(answer) def threeChain(listNums): for i in range(len(listNums)): for j in range(i+1,len(listNums)): if (2*listNums[j]-listNums[i]) in listNums: print str(listNums[i])+str(listNums[j])+str(2*listNums[j]-listNums[i]) return True return False candidates=[] for a in range(10): for b in range(10): for c in range(10): for d in range(1,min(a,b,c)+1): num=d*1000+c*100+b*10+a if isprime(num): if threeChain(primePermute(num)): candidates.append(num) # Doesn't return in the exact form, but the answer's there.
def p(A, B): if isprime(int(str(A) + str(B))) and isprime(int(str(B) + str(A))): return True return False
# No need to check lower right corners. from myFunctions import isprime primes = 3 layers = 2 while 1.0 * primes / (4 * layers - 3) > .1: if isprime((2 * layers - 1)**2 + (2 * layers)): primes += 1 if isprime((2 * layers - 1)**2 + 2 * (2 * layers)): primes += 1 if isprime((2 * layers - 1)**2 + 3 * (2 * layers)): primes += 1 layers += 1 print 2 * layers - 1
from myFunctions import primes, isprime prime = primes(10000) sum = 0 maxLength = 0 while sum <= 10**6: sum += prime[maxLength] maxLength += 1 found = False for runLength in range(maxLength - 1, 0, -1): for i in range(maxLength - runLength): sum = 0 for j in range(i, i + runLength): sum += prime[j] if isprime(sum): print sum found = True break if found: break