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.


: prime? ( n -- ? ) here + c@ 0= ;
: notprime! ( n -- ) here + 1 swap c! ;
 
: prime_sieve ( n -- )
  here over erase
  0 notprime!
  1 notprime!
  2
  begin
    2dup dup * >
  while
    dup prime? if
      2dup dup * do
        i notprime!
      dup +loop
    then
    1+
  repeat
  2drop ;
 
: digit_sum ( u -- u )
  dup 10 < if exit then
  10 /mod recurse + ;
 
: print_additive_primes ( n -- )
  ." Additive primes less than " dup 1 .r ." :" cr
  dup prime_sieve
  0 swap
  1 do
    i prime? if
      i digit_sum prime? if
        i 3 .r
        1+ dup 10 mod 0= if cr else space then
      then
    then
  loop
  cr . ." additive primes found." cr ;
 
500 print_additive_primes
bye