The Smarandache prime-digital sequence (SPDS for brevity) is the sequence of primes whose digits are themselves prime.

For example 257 is an element of this sequence because it is prime itself and its digits: 2, 5 and 7 are also prime.

Task
 Show the first 25 SPDS primes.
 Show the hundredth SPDS prime.


See also

 OEIS A019546: Primes whose digits are primes.
 https://www.scribd.com/document/214851583/On-the-Smarandache-prime-digital-subsequence-sequences


INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
BYTE FUNC IsZero(REAL POINTER a)
  CHAR ARRAY s(10)
 
  StrR(a,s)
  IF s(0)=1 AND s(1)='0 THEN
    RETURN (1)
  FI
RETURN (0)
 
CARD FUNC MyMod(CARD a,b)
  REAL ar,br,dr
  CARD d,m
 
  IF a>32767 THEN
    ;Built-in DIV and MOD
    ;do not work properly
    ;for numbers greater than 32767
    IntToReal(a,ar)
    IntToReal(b,br)
    RealDiv(ar,br,dr)
    d=RealToInt(dr)
    m=a-d*b
  ELSE
    m=a MOD b
  FI
RETURN (m)
 
BYTE FUNC IsPrime(CARD a)
  CARD i
 
  IF a<=1 THEN
    RETURN (0)
  FI
 
  i=2
  WHILE i*i<=a
  DO
    IF MyMod(a,i)=0 THEN
      RETURN (0)
    FI
    i==+1
  OD
RETURN (1)
 
BYTE FUNC AllDigitsArePrime(CARD a)
  BYTE i
  CHAR ARRAY s
  CHAR c
 
  StrC(a,s)
  FOR i=1 TO s(0)
  DO
    c=s(i)
    IF c#'2 AND c#'3 AND c#'5 AND c#'7 THEN
      RETURN (0)
    FI
  OD
RETURN (1)
 
PROC Main()
  BYTE count
  CARD a
 
  Put(125) PutE() ;clear screen
  PrintE("Sequence from 1st to 25th:")
  count=0 a=1
  DO
    IF AllDigitsArePrime(a)=1 AND IsPrime(a)=1 THEN
      count==+1
      IF count<=25 THEN
        PrintC(a) Put(32)
      ELSEIF count=100 THEN
        PrintF("%E%E100th: %U%E",a)
        EXIT
      FI
    FI
    a==+1
  OD
RETURN