summaryrefslogtreecommitdiff
path: root/Problem35.py
diff options
context:
space:
mode:
authorJoshua Drake <joshua.drake@ditchwitch.com>2023-04-07 08:13:49 -0500
committerJoshua Drake <joshua.drake@ditchwitch.com>2023-04-07 08:13:49 -0500
commit1161f9a034de06a63538e3a9a0b7717098c744d9 (patch)
tree55bb842b2daa4f096eb7916a8d3630426fc1c376 /Problem35.py
Initial CommitHEADmaster
Diffstat (limited to 'Problem35.py')
-rw-r--r--Problem35.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Problem35.py b/Problem35.py
new file mode 100644
index 0000000..5dd9049
--- /dev/null
+++ b/Problem35.py
@@ -0,0 +1,33 @@
+import math
+def rotate(n):
+ n = str(n)
+ m = ""
+ m+=n[len(n)-1]
+ for x in range(0,len(n)-1):
+ m+=n[x]
+ return int(m)
+def isPrime(n):
+ 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 areRotationsPrime(n):
+ m = rotate(n)
+ if isPrime(n) == False: return False
+ while(m != n):
+ if isPrime(m) == False: return False
+ else: m = rotate(m)
+ return True
+n, count = nextPrime(1000000), 0
+while(n > 1):
+ if areRotationsPrime(n) == True:
+ count+=1
+ print(n)
+ n = nextPrime(n)
+print("The Answer is:",count)
+
+