summaryrefslogtreecommitdiff
path: root/Problem51.py
blob: da9410ca4b45876284aeae6022dd0f01c442a891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Unfinished
import math
def isPrime(n):
    if n < 2: return False
    for x in range(2,int(math.sqrt(n)+1)):
        if n%x == 0: return False
    return True
def nextPrime(n):
    n+=1
    while isPrime(n) == False:
        n+=1
    return n
def countReplacementPrimes(n):
    strn = str(n)
    primecount = 0
    m = ""
    largestPrimeCount = 0
    for x in range(0,len(strn)): #selects position to be swapped
        primecount = 0
        for replacementValue in range(0, 10): #increments replacement value
            m = ""
            for y in range(0,len(strn)): #selects location within passed number
                if y == x:
                    m += str(replacementValue)
                else:
                    m += strn[y]
            if(isPrime(int(m))) == True: primecount +=1
            if primecount == 8: return True
    return False
print(countReplacementPrimes(121313))
#print(isPrime(int("70")))
# x = nextPrime(0)
# while countReplacementPrimes(x) == False:
#     x = nextPrime(x)
#     print(x)