Exemple #1
0
from black_box import rots, isprime
circlist = []

allnums = range(1000000,2,-1)

for i in allnums:
	print (i)
	numlist = []
	circ = True
	if isprime(i):
		numlist = rots(i)
		for num in numlist:
			if not isprime(num):
				circ = False
				break
		
		if circ:
			for num in numlist:
				circlist.append(num)
				if num in allnums:
					allnums.pop(allnums.index(num))
				
#print (circlist)
print (len(circlist))
Exemple #2
0
from black_box import isprime

file = open("primeList.txt","w")

for i in [val for val in range(1,1000001) if isprime(val)]:
	file.write(str(i) + " ")

file.close()
Exemple #3
0

from black_box import isprime

maxVal = 100
primesToMax = []

for i in range(1, maxVal):
    if isprime(i):
        primesToMax.append(i)

span = 1
maxSpan = 1
maxSpanSum = 0
spanSum = 0
spanStart = 0
found = False

print("HERE")

while spanSum < maxVal:
    span += 1
    spanSum = sum(primesToMax[spanStart:spanStart + span])
    if(isprime(spanSum)):
        if(span > maxSpan):
            maxSpan = span
            maxSpanSum = spanSum


print("NOW HERE")
Exemple #4
0
# If one complete new layer is wrapped around the spiral above, 
# a square spiral with side length 9 will be formed. If this 
# process is continued, what is the side length of the square 
# spiral for which the ratio of primes along both diagonals 
# first falls below 10%?

from black_box import isprime

layer = 1
done = False
diagList = [1]
primes = 0
diags = 1
lastDiag = 1

while not done:
    for iterate in range(4):
        space = layer * 2 - 1
        lastDiag = lastDiag + space + 1
        diags += 1
        if(isprime(lastDiag)):
            primes += 1
    layer += 1
    

    primePercent = primes / diags
    if(primePercent < 0.1):
        done = True

print(space + 2)
from black_box import isprime

file = open("../Reference/primeList.txt", "w")
numran = range(2,2000000)
for i in numran:
	if isprime(i):
		file.write( str(i) + " ")

file.close()
Exemple #6
0
# By listing the first six prime numbers: 2, 3, 5, 7, 11, 
# and 13, we can see that the 6th prime is 13.

# What is the 10 001st prime number?
from black_box import isprime

found = False
nth = 0
num = 1
while not found:
    num += 1
    if isprime(num):
        nth += 1
    if nth == 10001:
        found = True

print(num)
Exemple #7
0
from black_box import isprime

trunclist = []

done = False
num = 10
while not done:
	num += 1
	if isprime(num):
		trunc = True
		numst = str(num)
		numst1 = str(num)
		numst2 = str(num)
		for i in range(len(numst) - 1):
			numst1 = numst1[1:len(numst1)]
			numst2 = numst2[0:len(numst2) - 1]
			if not (isprime(int(numst1)) and isprime(int(numst2))):
				trunc = False
				break
			
		
	else:
		trunc = False
		
	if trunc:
		trunclist.append(num)
		print (num)
	
	if len(trunclist) == 11:
		done = True
		
Exemple #8
0
#that produces the maximum number of primes for consecutive values of n, 
#starting with n = 0.

from black_box import isprime
from math import sqrt

longest = {"vals": [0,0], "counter": 0}

for a in range(-999,1000):
	print(a)
	for b in range(-999,1000):
		done = False
		counter = 0
		n = 0
		att = 0
		
		while not done:
			att = n**2 + a*n + b
			if isprime(att):
				counter += 1
			else:
				done = True
			n += 1
			
		if counter > longest["counter"]:
			longest["counter"] = counter
			longest["vals"] = [a,b]
			
			
print (longest)
print ("Product: " + str(longest["vals"][0] * longest["vals"][1]))
Exemple #9
0
        allPerms = True
    else:
        allPerms = False

    return allPerms

numFound = 0

for i in range(1000, 10000):
    half = int( ( 10000 - i ) / 2)
    for j in range(1, half):
        num1 = i
        num2 = i + j
        num3 = i + 2*j

        if(isprime(num1) and isprime(num2) and isprime(num3)):
            if(allPerm(num1, num2, num3)):
                numFound += 1
                print(str(num1) + " " + str(num2) + " " + str(num3))
                if(numFound >= 2):
                    break

    if(numFound >= 2):
        break






Exemple #10
0
from itertools import permutations
from black_box import isprime

done = False
num = 1234567
stlist = list( permutations(str(num)) )

biggest = 3
for blah in stlist:
	numst = ''
	for c in blah:
		numst = numst+c
	newnum = int(numst)
	if isprime(newnum):
		if newnum > biggest:
			biggest = newnum
			
print (biggest)
Exemple #11
0
# The prime factors of 13195 are 5, 7, 13 and 29.

# What is the largest prime factor of the number 600851475143 ?


from black_box import isprime
from black_box import alldivs

divList = alldivs(600851475143)

answer = divList[-1]
for num in reversed(divList):
    if(isprime(num)):
        answer = num
        break

print(answer)
Exemple #12
0
from black_box import isprime
from black_box import list2int
from black_box import numperms
from black_box import numcirc

answer = []
#allprimes = []
numran = range(1000000,2,-1)
#for i in numran:
#	if isprime(i):
#		allprimes.append(i)
#
#print (len(allprimes))

for i in numran:
	if isprime(i):
		print (i)
		nums = numcirc(i)
		allprime = True
		for j in nums:
			if not isprime(j):
				allprime = False
				break
		if allprime:
			for j in nums:
				if j not in answer:
					answer.append(j)
				if j in numran:
					numran.pop(numran.index(j))

#answer.sort()