aboutsummaryrefslogtreecommitdiff
path: root/challenge-158/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-09-28 21:03:54 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-09-28 21:03:54 +0100
commit45ae6460d987618b7ca6016b89f7722c848893fa (patch)
tree845871ca1bc5bcedd4e57574aac893a52fd5f164 /challenge-158/paulo-custodio/python/ch-1.py
parentbcbb8e543ac9ad74cf70fb749a5f7f917e78abb2 (diff)
downloadperlweeklychallenge-club-45ae6460d987618b7ca6016b89f7722c848893fa.tar.gz
perlweeklychallenge-club-45ae6460d987618b7ca6016b89f7722c848893fa.tar.bz2
perlweeklychallenge-club-45ae6460d987618b7ca6016b89f7722c848893fa.zip
Add Python solution to challenge 158
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))))