aboutsummaryrefslogtreecommitdiff
path: root/challenge-158/paulo-custodio/python/ch-1.py
blob: ad3b7825eb72e7a99fc62b64f082bd104421be83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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))))