aboutsummaryrefslogtreecommitdiff
path: root/challenge-158/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-158/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-158/paulo-custodio/python/ch-1.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-158/paulo-custodio/python/ch-1.py b/challenge-158/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..ad3b7825eb
--- /dev/null
+++ b/challenge-158/paulo-custodio/python/ch-1.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+# Challenge 158
+#
+# TASK #1 > Additive Primes
+# Submitted by: Mohammad S Anwar
+# Write a script to find out all Additive Primes <= 100.
+#
+# Additive primes are prime numbers for which the sum of their decimal digits
+# are also primes.
+#
+#
+# Output
+# 2, 3, 5, 7, 11, 23, 29, 41, 43, 47, 61, 67, 83, 89
+
+from sympy import isprime, nextprime
+
+def additive_primes(limit):
+ out = []
+ prime = 2
+ while prime < limit:
+ if isprime(sum(int(digit) for digit in str(prime))):
+ out.append(prime)
+ prime = nextprime(prime)
+ return out
+
+print(", ".join(map(str, additive_primes(100))))