Special neighbor primes: Difference between revisions

From Rosetta Code
Content added Content deleted
(Blanked the page)
No edit summary
Line 1: Line 1:
{{Draft task}}

;Task:Let &nbsp; ('''p<sub>1</sub>''', &nbsp;'''p<sub>2</sub>''') &nbsp; are neighbourprimes. Find and show here in base ten '''p<sub>1</sub> + &nbsp; p<sub>2</sub> &nbsp; - 1''' &nbsp; where &nbsp; '''p<sub>1</sub>, &nbsp; p<sub>2</sub> &nbsp;&lt;&nbsp; 100'''.

<br><br>

=={{header|Ring}}==
<lang ring>
load "stdlib.ring"

see "working..." + nl
see "Special neighbour primes are:" + nl
row = 0
oldPrime = 2

for n = 3 to 100
if isprime(n) and isprime(oldPrime)
sum = oldPrime + n - 1
if isprime(sum)
row++
see "" + oldPrime + "," + n + " => " + sum + nl
ok
oldPrime = n
ok
next

see "Found " + row + " special neighbour primes"
see "done..." + nl
</lang>
{{out}}
<pre>
working...
Special twin primes are:
3,5 => 7
5,7 => 11
7,11 => 17
11,13 => 23
13,17 => 29
19,23 => 41
29,31 => 59
31,37 => 67
41,43 => 83
43,47 => 89
61,67 => 127
67,71 => 137
73,79 => 151
Found 13 special twin primesdone...
</pre>

Revision as of 04:54, 6 August 2021

Special neighbor 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
Let   (p1,  p2)   are neighbourprimes. Find and show here in base ten p1 +   p2   - 1   where   p1,   p2  <  100.



Ring

<lang ring> load "stdlib.ring"

see "working..." + nl see "Special neighbour primes are:" + nl row = 0 oldPrime = 2

for n = 3 to 100

   if isprime(n) and isprime(oldPrime) 
      sum = oldPrime + n - 1
      if isprime(sum)
         row++
         see "" + oldPrime + "," + n + " => " + sum + nl
      ok
      oldPrime = n
   ok

next

see "Found " + row + " special neighbour primes" see "done..." + nl </lang>

Output:
working...
Special twin primes are:
3,5 => 7
5,7 => 11
7,11 => 17
11,13 => 23
13,17 => 29
19,23 => 41
29,31 => 59
31,37 => 67
41,43 => 83
43,47 => 89
61,67 => 127
67,71 => 137
73,79 => 151
Found 13 special twin primesdone...