Smarandache prime-digital sequence

From Rosetta Code
Revision as of 08:40, 31 May 2019 by CalmoSoft (talk | contribs) (Created page with "{{task|Calmo primes}} Prime p is Calmo prime if each its digit is also prime. ;Task: Show first 25 Calmo primes. Show hundrest Calmo prime. =={{header|Ring}}== <lang ring>...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Smarandache prime-digital sequence
You are encouraged to solve this task according to the task description, using any language you may know.

Prime p is Calmo prime if each its digit is also prime.

Task

Show first 25 Calmo primes. Show hundrest Calmo prime.

Ring

<lang ring>

  1. Project: Calmo primes

load "stdlib.ring" limit = 25 max = 300000 num = 0 see "working..." + nl see "wait for done..." + nl see "First 25 Calmo primes are:" + nl for n = 1 to max

   if isprime(n)
      res = calmo(n)
      if res = 1
         num = num + 1
         if num < limit + 1
            see "" + num + ". " + n + nl
         ok
         if num = 100
            see "The hundrest Calmo prime is:" + nl
            see "" + num + ". " + n + nl
            exit
         ok
      ok
   ok

next see "done..." + nl

func calmo(p)

    sp = string(p)
    for n = 1 to len(sp)
        if not isprime(sp[n])
           return 0
        ok
    next
    return 1

</lang>

working...
wait for done...
First 25 Calmo primes are:
1. 2
2. 3
3. 5
4. 7
5. 23
6. 37
7. 53
8. 73
9. 223
10. 227
11. 233
12. 257
13. 277
14. 337
15. 353
16. 373
17. 523
18. 557
19. 577
20. 727
21. 733
22. 757
23. 773
24. 2237
25. 2273
The hundrest Calmo prime is:
100. 33223
done...