summaryrefslogtreecommitdiff
path: root/Problem37.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 /Problem37.py
Initial CommitHEADmaster
Diffstat (limited to 'Problem37.py')
-rw-r--r--Problem37.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/Problem37.py b/Problem37.py
new file mode 100644
index 0000000..cd7bc98
--- /dev/null
+++ b/Problem37.py
@@ -0,0 +1,34 @@
+#Completed oon 9/13/2021 14:29
+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 truncatable(n):
+ n = str(n)
+ for x in range(0,len(n)):
+ m = ""
+ for y in range(0,len(n)-x):
+ m += n[y]
+ if isPrime(int(m)) == False: return False
+ #repeat but left to right
+ for x in range(0,len(n)):
+ m = ""
+ for y in range(x,len(n)):
+ m += n[y]
+ if isPrime(int(m)) == False: return False
+ return True
+sum,count,x = 0,0,nextPrime(7)
+while count < 11:
+ if truncatable(x) == True:
+ sum += x
+ count += 1
+ x = nextPrime(x)
+print("Answer is:", sum)
+ \ No newline at end of file