Rebol3 Code Examplex


Neighbour primes

Find and show primes p such that p*q+2 is prime, where q is next prime after p and p < 500

Rebol [
    title: "Rosetta code: Neighbour primes"
    file:  %Neighbour_primes.r3
    url:   https://rosettacode.org/wiki/Neighbour_primes
]

primes-up-to-500: collect [
    repeat i 500 [if prime? i [keep i]]
]

print "p       q       p*q+2"
print "------------------------"
forall primes-up-to-500 [
    set [p q] primes-up-to-500
    if all [q prime? (pq+2: p * q + 2)] [
        printf [8 8 ][p q pq+2]
    ]
]

Output:

p       q       p*q+2
------------------------
3       5       17
5       7       37
7       11      79
13      17      223
19      23      439
67      71      4759
149     151     22501
179     181     32401
229     233     53359
239     241     57601
241     251     60493
269     271     72901
277     281     77839
307     311     95479
313     317     99223
397     401     159199
401     409     164011
419     421     176401
439     443     194479
487     491     239119