Piprimes

From Rosetta Code
Revision as of 05:37, 2 April 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} Category:Prime Numbers ;Task: pi(n), the number of primes <= n, where '''épi(n) < 22''' <br><br> =={{header|Ring}}== <lang ring> load "stdlib.ring" decim...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Piprimes 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

pi(n), the number of primes <= n, where épi(n) < 22

Ring

<lang ring> load "stdlib.ring"

decimals(0) see "working..." + nl see "Piprimes are:" + nl

row = 0 limit1 = 400 Prim = []

for n = 1 to limit1

   if isprime(n)
      add(Prim,n)
   ok

next

for n = 1 to len(Prim)

   for m = 1 to len(Prim)
       if Prim[m] > n
          ind = m - 1
          exit
       ok
   next
   row = row + 1
   see "" + ind + " "
   if row%10 = 0
      see nl
   ok

next

see nl + "Found " + row + " Piprimes." + nl see "done..." + nl </lang>

Output:
working...
Piprimes are:
0 1 2 2 3 3 4 4 4 4 
5 5 6 6 6 6 7 7 8 8 
8 8 9 9 9 9 9 9 10 10 
11 11 11 11 11 11 12 12 12 12 
13 13 14 14 14 14 15 15 15 15 
15 15 16 16 16 16 16 16 17 17 
18 18 18 18 18 18 19 19 19 19 
20 20 21 21 21 21 21 21 
Found 78 Piprimes.
done...