Erdős-primes: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with "{{Draft task|Prime Numbers}} ;Definitions In mathematics, '''Erdős-primes''' are prime numbers which sum of digits are primes. ;Task Write a program to determine (and show...")
 
No edit summary
Line 36: Line 36:
next
next


see nl + "found " + row + " Erdös-prime pairs." + nl
see nl + "found " + row + " Erdös-prime." + nl
see "done..." + nl
see "done..." + nl
</lang>
</lang>
Line 49: Line 49:
353 359 373 379 397 401 409 421 443 449
353 359 373 379 397 401 409 421 443 449
461 463 467 487
461 463 467 487
found 54 Erdös-prime pairs.
found 54 Erdös-prime.
done...
done...
</pre>
</pre>

Revision as of 05:10, 19 March 2021

Erdős-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.
Definitions

In mathematics, Erdős-primes are prime numbers which sum of digits are primes.

Task

Write a program to determine (and show here) all Erdős-primes whose elements are less than 500.

Optionally, show the number of Erdős-primes.

Ring

<lang ring> load "stdlib.ring"

see "working..." + nl see "Erdős-primes are:" + nl

row = 0 limit = 500

for n = 1 to limit

   num = 0
   if isprime(n) 
      strn = string(n)
      for m = 1 to len(strn)
          num = num + number(strn[m])
      next
      if isprime(num)
         row = row + 1
         see "" + n + " "
         if row%10 = 0
            see nl
         ok
      ok
   ok

next

see nl + "found " + row + " Erdös-prime." + nl see "done..." + nl </lang>

Output:
working...
Erdős-primes are:
2 3 5 7 11 23 29 41 43 47 
61 67 83 89 101 113 131 137 139 151 
157 173 179 191 193 197 199 223 227 229 
241 263 269 281 283 311 313 317 331 337 
353 359 373 379 397 401 409 421 443 449 
461 463 467 487 
found 54 Erdös-prime.
done...