Definitions
In mathematics, additive primes are prime numbers for which the sum of their decimal digits are also primes.



Task
Write a program to determine (and show here) all additive primes less than 500.

Optionally, show the number of additive primes.



Also see

   the OEIS entry:   A046704 additive primes.
   the prime-numbers entry:   additive primes.
   the geeks for geeks entry: additive prime number.
   the prime-numbers fandom: additive primes.


import Data.List (unfoldr)
 
-- infinite list of primes
primes = 2 : sieve [3,5..]
  where sieve (x:xs) = x : sieve (filter (\y -> y `mod` x /= 0) xs)
 
-- primarity test, effective for numbers less then billion
isPrime n = all (\p -> n `mod` p /= 0) $ takeWhile (< sqrtN) primes
  where sqrtN = round . sqrt . fromIntegral $ n
 
-- decimal digits of a number
digits = unfoldr f
  where f 0 = Nothing
        f n = let (q, r) = divMod n 10 in Just (r,q)
 
-- test for an additive prime 
isAdditivePrime n = isPrime n && (isPrime . sum . digits) n
 