Substring primes

From Rosetta Code
Revision as of 06:44, 5 April 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} Category:Prime Numbers ;Task: Numbers in which all substrings are primes, where '''n < 500''' <br><br> =={{header|Ring}}== <lang ring> load "stdlib.ring"...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Substring primes is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

Numbers in which all substrings are primes, where n < 500

Ring

<lang ring> load "stdlib.ring"

see "working..." + nl see "Numbers in which all substrings are primes:" + nl

row = 0 limit1 = 500

for n = 1 to limit1

   flag = 1
   strn = string(n)
   for m = 1 to len(strn)
       for p = 1 to len(strn)
           temp = substr(strn,m,p)
           if temp != ""
               if isprime(number(temp))
                  flag = 1
               else
                  flag = 0
                  exit 2
               ok
           ok
        next
     next
     if flag = 0
     ok
     if flag = 1
        see "" + n + " "
     ok 

next

see nl + "Found " + row + " numbers in which all substrings are primes" + nl see "done..." + nl </lang>

Output:
working...
Numbers in which all substrings are primes:
2 3 5 7 23 37 53 73 373 
Found 9 numbers in which all substrings are primes
done...