From 1161f9a034de06a63538e3a9a0b7717098c744d9 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Fri, 7 Apr 2023 08:13:49 -0500 Subject: Initial Commit --- Problem51.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Problem51.py (limited to 'Problem51.py') diff --git a/Problem51.py b/Problem51.py new file mode 100644 index 0000000..da9410c --- /dev/null +++ b/Problem51.py @@ -0,0 +1,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) + + + \ No newline at end of file -- cgit v1.2.3