I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

Triplet of three numbers

From Rosetta Code
Triplet of three numbers 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

Numbers   n   such that the three numbers   n-1,   n+3,  and  n+5   are all prime,   where   n < 6000.


ALGOL 68[edit]

BEGIN # find numbers n where n-1, n+3 and n+5 are prime #
INT max number = 6000;
# sieve the primes up to max number #
[ 1 : max number ]BOOL prime;
prime[ 1 ] := FALSE; prime[ 2 ] := TRUE;
FOR i FROM 3 BY 2 TO UPB prime DO prime[ i ] := TRUE OD;
FOR i FROM 4 BY 2 TO UPB prime DO prime[ i ] := FALSE OD;
FOR i FROM 3 BY 2 TO ENTIER sqrt( max number ) DO
IF prime[ i ] THEN FOR s FROM i * i BY i + i TO UPB prime DO prime[ s ] := FALSE OD FI
OD;
# returns a string represention of n #
OP TOSTRING = ( INT n )STRING: whole( n, 0 );
# look for suitable numbers #
# 2 is clearly not a member of the required numbers, so we start at 3 #
INT n count := 0;
FOR n FROM 3 TO max number - 5 DO
IF prime[ n - 1 ] AND prime[ n + 3 ] AND prime[ n + 5 ] THEN
print( ( " (", TOSTRING n, " | ", TOSTRING ( n - 1 ), ", ", TOSTRING ( n + 3 ), ", ", TOSTRING ( n + 5 ), ")" ) );
n count +:= 1;
IF n count MOD 4 = 0 THEN print( ( newline ) ) FI
FI
OD;
print( ( newline, "Found ", TOSTRING n count, " triplets", newline ) )
END
Output:
 (8 | 7, 11, 13) (14 | 13, 17, 19) (38 | 37, 41, 43) (68 | 67, 71, 73)
 (98 | 97, 101, 103) (104 | 103, 107, 109) (194 | 193, 197, 199) (224 | 223, 227, 229)
 (278 | 277, 281, 283) (308 | 307, 311, 313) (458 | 457, 461, 463) (614 | 613, 617, 619)
 (824 | 823, 827, 829) (854 | 853, 857, 859) (878 | 877, 881, 883) (1088 | 1087, 1091, 1093)
 (1298 | 1297, 1301, 1303) (1424 | 1423, 1427, 1429) (1448 | 1447, 1451, 1453) (1484 | 1483, 1487, 1489)
 (1664 | 1663, 1667, 1669) (1694 | 1693, 1697, 1699) (1784 | 1783, 1787, 1789) (1868 | 1867, 1871, 1873)
 (1874 | 1873, 1877, 1879) (1994 | 1993, 1997, 1999) (2084 | 2083, 2087, 2089) (2138 | 2137, 2141, 2143)
 (2378 | 2377, 2381, 2383) (2684 | 2683, 2687, 2689) (2708 | 2707, 2711, 2713) (2798 | 2797, 2801, 2803)
 (3164 | 3163, 3167, 3169) (3254 | 3253, 3257, 3259) (3458 | 3457, 3461, 3463) (3464 | 3463, 3467, 3469)
 (3848 | 3847, 3851, 3853) (4154 | 4153, 4157, 4159) (4514 | 4513, 4517, 4519) (4784 | 4783, 4787, 4789)
 (5228 | 5227, 5231, 5233) (5414 | 5413, 5417, 5419) (5438 | 5437, 5441, 5443) (5648 | 5647, 5651, 5653)
 (5654 | 5653, 5657, 5659) (5738 | 5737, 5741, 5743)
Found 46 triplets

Arturo[edit]

lst: select 3..6000 'x
-> all? @[prime? x-1 prime? x+3 prime? x+5]
 
loop split.every: 10 lst 'a ->
print map a => [pad to :string & 5]
Output:
    8    14    38    68    98   104   194   224   278   308 
  458   614   824   854   878  1088  1298  1424  1448  1484 
 1664  1694  1784  1868  1874  1994  2084  2138  2378  2684 
 2708  2798  3164  3254  3458  3464  3848  4154  4514  4784 
 5228  5414  5438  5648  5654  5738

AWK[edit]

 
# syntax: GAWK -f TRIPLET_OF_THREE_NUMBERS.AWK
BEGIN {
start = 1
stop = 6000
print(" N N-1 N+3 N+5")
print("----- ---- ---- ----")
for (i=start; i<=stop; i++) {
if (is_prime(i-1) && is_prime(i+3) && is_prime(i+5)) {
printf("%4d: %4d %4d %4d\n",i,i-1,i+3,i+5)
count++
}
}
printf("Triplet of three numbers %d-%d: %d\n",start,stop,count)
exit(0)
}
function is_prime(x, i) {
if (x <= 1) {
return(0)
}
for (i=2; i<=int(sqrt(x)); i++) {
if (x % i == 0) {
return(0)
}
}
return(1)
}
 
Output:
   N   N-1  N+3  N+5
----- ---- ---- ----
   8:    7   11   13
  14:   13   17   19
  38:   37   41   43
  68:   67   71   73
  98:   97  101  103
 104:  103  107  109
 194:  193  197  199
 224:  223  227  229
 278:  277  281  283
 308:  307  311  313
 458:  457  461  463
 614:  613  617  619
 824:  823  827  829
 854:  853  857  859
 878:  877  881  883
1088: 1087 1091 1093
1298: 1297 1301 1303
1424: 1423 1427 1429
1448: 1447 1451 1453
1484: 1483 1487 1489
1664: 1663 1667 1669
1694: 1693 1697 1699
1784: 1783 1787 1789
1868: 1867 1871 1873
1874: 1873 1877 1879
1994: 1993 1997 1999
2084: 2083 2087 2089
2138: 2137 2141 2143
2378: 2377 2381 2383
2684: 2683 2687 2689
2708: 2707 2711 2713
2798: 2797 2801 2803
3164: 3163 3167 3169
3254: 3253 3257 3259
3458: 3457 3461 3463
3464: 3463 3467 3469
3848: 3847 3851 3853
4154: 4153 4157 4159
4514: 4513 4517 4519
4784: 4783 4787 4789
5228: 5227 5231 5233
5414: 5413 5417 5419
5438: 5437 5441 5443
5648: 5647 5651 5653
5654: 5653 5657 5659
5738: 5737 5741 5743
Triplet of three numbers 1-6000: 46

BASIC[edit]

10 DEFINT A-Z: N=6000
20 DIM P(N+5)
30 FOR I=2 TO SQR(N)
40 IF NOT P(I) THEN FOR J=I*2 TO N STEP I: P(J)=1: NEXT
50 NEXT
60 FOR I=3 TO N
70 IF P(I-1) OR P(I+3) OR P(I+5) GOTO 90
80 PRINT USING "####,: ####, ####, ####,";I;I-1;I+3;I+5
90 NEXT
Output:
    8:     7    11    13
   14:    13    17    19
   38:    37    41    43
   68:    67    71    73
   98:    97   101   103
  104:   103   107   109
  194:   193   197   199
  224:   223   227   229
  278:   277   281   283
  308:   307   311   313
  458:   457   461   463
  614:   613   617   619
  824:   823   827   829
  854:   853   857   859
  878:   877   881   883
1,088: 1,087 1,091 1,093
1,298: 1,297 1,301 1,303
1,424: 1,423 1,427 1,429
1,448: 1,447 1,451 1,453
1,484: 1,483 1,487 1,489
1,664: 1,663 1,667 1,669
1,694: 1,693 1,697 1,699
1,784: 1,783 1,787 1,789
1,868: 1,867 1,871 1,873
1,874: 1,873 1,877 1,879
1,994: 1,993 1,997 1,999
2,084: 2,083 2,087 2,089
2,138: 2,137 2,141 2,143
2,378: 2,377 2,381 2,383
2,684: 2,683 2,687 2,689
2,708: 2,707 2,711 2,713
2,798: 2,797 2,801 2,803
3,164: 3,163 3,167 3,169
3,254: 3,253 3,257 3,259
3,458: 3,457 3,461 3,463
3,464: 3,463 3,467 3,469
3,848: 3,847 3,851 3,853
4,154: 4,153 4,157 4,159
4,514: 4,513 4,517 4,519
4,784: 4,783 4,787 4,789
5,228: 5,227 5,231 5,233
5,414: 5,413 5,417 5,419
5,438: 5,437 5,441 5,443
5,648: 5,647 5,651 5,653
5,654: 5,653 5,657 5,659
5,738: 5,737 5,741 5,743

BCPL[edit]

get "libhdr"
manifest $( limit = 6000 $)
 
let sieve(p, n) be
$( p!0 := false
p!1 := false
for i=2 to n do p!i := true
for i=2 to n/2
if p!i
$( let j = i*2
while j <= n
$( p!j := false
j := j+i
$)
$)
$)
 
let triplet(p, n) = n>=2 & p!(n-1) & p!(n+3) & p!(n+5)
 
let start() be
$( let prime = getvec(limit)
sieve(prime, limit)
for i=2 to limit
if triplet(prime, i) do
writef("%I4: %I4, %I4, %I4*N", i, i-1, i+3, i+5)
freevec(prime)
$)
Output:
   8:    7,   11,   13
  14:   13,   17,   19
  38:   37,   41,   43
  68:   67,   71,   73
  98:   97,  101,  103
 104:  103,  107,  109
 194:  193,  197,  199
 224:  223,  227,  229
 278:  277,  281,  283
 308:  307,  311,  313
 458:  457,  461,  463
 614:  613,  617,  619
 824:  823,  827,  829
 854:  853,  857,  859
 878:  877,  881,  883
1088: 1087, 1091, 1093
1298: 1297, 1301, 1303
1424: 1423, 1427, 1429
1448: 1447, 1451, 1453
1484: 1483, 1487, 1489
1664: 1663, 1667, 1669
1694: 1693, 1697, 1699
1784: 1783, 1787, 1789
1868: 1867, 1871, 1873
1874: 1873, 1877, 1879
1994: 1993, 1997, 1999
2084: 2083, 2087, 2089
2138: 2137, 2141, 2143
2378: 2377, 2381, 2383
2684: 2683, 2687, 2689
2708: 2707, 2711, 2713
2798: 2797, 2801, 2803
3164: 3163, 3167, 3169
3254: 3253, 3257, 3259
3458: 3457, 3461, 3463
3464: 3463, 3467, 3469
3848: 3847, 3851, 3853
4154: 4153, 4157, 4159
4514: 4513, 4517, 4519
4784: 4783, 4787, 4789
5228: 5227, 5231, 5233
5414: 5413, 5417, 5419
5438: 5437, 5441, 5443
5648: 5647, 5651, 5653
5654: 5653, 5657, 5659
5738: 5737, 5741, 5743

C[edit]

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#define LIMIT 6000
 
char *primes(unsigned int limit) {
char *p = malloc(limit + 1);
int i, j, sqr = sqrt(limit);
 
p[0] = p[1] = 0;
memset(p+2, 1, limit-1);
for (i=2; i<=sqr; i++)
if (p[i])
for (j=i*2; j<=limit; j+=i)
p[j] = 0;
 
return p;
}
 
int triplet(const char *p, unsigned int n) {
return n >= 2 && p[n-1] && p[n+3] && p[n+5];
}
 
int main() {
char *p = primes(LIMIT+5);
int i;
 
for (i=2; i<LIMIT; i++)
if (triplet(p, i))
printf("%4d: %4d, %4d, %4d\n", i, i-1, i+3, i+5);
 
free(p);
return 0;
}
Output:
   8:    7,   11,   13
  14:   13,   17,   19
  38:   37,   41,   43
  68:   67,   71,   73
  98:   97,  101,  103
 104:  103,  107,  109
 194:  193,  197,  199
 224:  223,  227,  229
 278:  277,  281,  283
 308:  307,  311,  313
 458:  457,  461,  463
 614:  613,  617,  619
 824:  823,  827,  829
 854:  853,  857,  859
 878:  877,  881,  883
1088: 1087, 1091, 1093
1298: 1297, 1301, 1303
1424: 1423, 1427, 1429
1448: 1447, 1451, 1453
1484: 1483, 1487, 1489
1664: 1663, 1667, 1669
1694: 1693, 1697, 1699
1784: 1783, 1787, 1789
1868: 1867, 1871, 1873
1874: 1873, 1877, 1879
1994: 1993, 1997, 1999
2084: 2083, 2087, 2089
2138: 2137, 2141, 2143
2378: 2377, 2381, 2383
2684: 2683, 2687, 2689
2708: 2707, 2711, 2713
2798: 2797, 2801, 2803
3164: 3163, 3167, 3169
3254: 3253, 3257, 3259
3458: 3457, 3461, 3463
3464: 3463, 3467, 3469
3848: 3847, 3851, 3853
4154: 4153, 4157, 4159
4514: 4513, 4517, 4519
4784: 4783, 4787, 4789
5228: 5227, 5231, 5233
5414: 5413, 5417, 5419
5438: 5437, 5441, 5443
5648: 5647, 5651, 5653
5654: 5653, 5657, 5659
5738: 5737, 5741, 5743

C#[edit]

How about some upper limits above 6000?

using System; using System.Collections.Generic; using System.Linq;
using T3 = System.Tuple<int, int, int>; using static System.Console;
class Program { static void Main() {
WriteLine(" \"N\": Prime Triplet Adjacent (to previous)\n" +
" ---- ----------------- -----------------------");
foreach(var lmt in new double[]{6e3, 1e5, 1e6, 1e7, 1e8}) {
var pr = PG.Primes((int)lmt); int l = 0, c = 0; bool a;
foreach (var t in pr) { c += (a = l == t.Item1) ? 1 : 0;
if (lmt < 1e5) WriteLine("{0,4}: {1,-18} {2}",
t.Item1 + 1, t, a ? " *" : ""); l = t.Item3; }
Console.WriteLine ("Up to {0:n0} there are {1:n0} prime triples, " +
"of which {2:n0} were found to be adjacent.", lmt, pr.Count(), c); } } }
 
class PG { static bool[] f; static bool isPrT(int x, int y, int z) {
if (x < 7) return false; return !f[x] && !f[y] && !f[z]; }
public static IEnumerable<T3> Primes(int l) { f = new bool[l += 6];
int j, lj, llj, lllj; j = lj = llj = lllj = 3;
for (int d = 8, s = 9; s < l; lllj = llj, llj = lj, lj = j, j += 2, s += d += 8)
if (!f[j]) { if (isPrT(lllj, lj, j)) yield return new T3(lllj, lj, j);
for (int k = s, i = j << 1; k < l; k += i) f[k] = true; }
for (; j < l; lllj = llj, llj = lj, lj = j, j += 2)
if (isPrT(lllj, lj, j)) yield return new T3(lllj, lj, j); } }
Output:
 "N":  Prime Triplet    Adjacent (to previous)
 ---- ----------------- -----------------------
   8: (7, 11, 13)        
  14: (13, 17, 19)        *
  38: (37, 41, 43)       
  68: (67, 71, 73)       
  98: (97, 101, 103)     
 104: (103, 107, 109)     *
 194: (193, 197, 199)    
 224: (223, 227, 229)    
 278: (277, 281, 283)    
 308: (307, 311, 313)    
 458: (457, 461, 463)    
 614: (613, 617, 619)    
 824: (823, 827, 829)    
 854: (853, 857, 859)    
 878: (877, 881, 883)    
1088: (1087, 1091, 1093) 
1298: (1297, 1301, 1303) 
1424: (1423, 1427, 1429) 
1448: (1447, 1451, 1453) 
1484: (1483, 1487, 1489) 
1664: (1663, 1667, 1669) 
1694: (1693, 1697, 1699) 
1784: (1783, 1787, 1789) 
1868: (1867, 1871, 1873) 
1874: (1873, 1877, 1879)  *
1994: (1993, 1997, 1999) 
2084: (2083, 2087, 2089) 
2138: (2137, 2141, 2143) 
2378: (2377, 2381, 2383) 
2684: (2683, 2687, 2689) 
2708: (2707, 2711, 2713) 
2798: (2797, 2801, 2803) 
3164: (3163, 3167, 3169) 
3254: (3253, 3257, 3259) 
3458: (3457, 3461, 3463) 
3464: (3463, 3467, 3469)  *
3848: (3847, 3851, 3853) 
4154: (4153, 4157, 4159) 
4514: (4513, 4517, 4519) 
4784: (4783, 4787, 4789) 
5228: (5227, 5231, 5233) 
5414: (5413, 5417, 5419) 
5438: (5437, 5441, 5443) 
5648: (5647, 5651, 5653) 
5654: (5653, 5657, 5659)  *
5738: (5737, 5741, 5743) 
Up to 6,000 there are 46 prime triples, of which 5 were found to be adjacent.
Up to 100,000 there are 248 prime triples, of which 11 were found to be adjacent.
Up to 1,000,000 there are 1,444 prime triples, of which 31 were found to be adjacent.
Up to 10,000,000 there are 8,677 prime triples, of which 161 were found to be adjacent.
Up to 100,000,000 there are 55,556 prime triples, of which 686 were found to be adjacent.

Cowgol[edit]

include "cowgol.coh";
 
const LIMIT := 6000;
 
var prime: uint8[LIMIT+5];
var i: @indexof prime;
var j: @indexof prime;
 
prime[0] := 0;
prime[1] := 0;
MemSet(&prime[2], 1, @bytesof prime-2);
i := 2;
while i <= @sizeof prime/2-1 loop
if prime[i] != 0 then
j := i*2;
while j <= @sizeof prime-1 loop
prime[j] := 0;
j := j+i;
end loop;
end if;
i := i+1;
end loop;
 
i := 2;
while i < LIMIT loop
if prime[i-1] & prime[i+3] & prime[i+5] != 0 then
print_i32(i as uint32);
print(": ");
print_i32(i as uint32-1);
print(", ");
print_i32(i as uint32+3);
print(", ");
print_i32(i as uint32+5);
print_nl();
end if;
i := i + 1;
end loop;
Output:
8: 7, 11, 13
14: 13, 17, 19
38: 37, 41, 43
68: 67, 71, 73
98: 97, 101, 103
104: 103, 107, 109
194: 193, 197, 199
224: 223, 227, 229
278: 277, 281, 283
308: 307, 311, 313
458: 457, 461, 463
614: 613, 617, 619
824: 823, 827, 829
854: 853, 857, 859
878: 877, 881, 883
1088: 1087, 1091, 1093
1298: 1297, 1301, 1303
1424: 1423, 1427, 1429
1448: 1447, 1451, 1453
1484: 1483, 1487, 1489
1664: 1663, 1667, 1669
1694: 1693, 1697, 1699
1784: 1783, 1787, 1789
1868: 1867, 1871, 1873
1874: 1873, 1877, 1879
1994: 1993, 1997, 1999
2084: 2083, 2087, 2089
2138: 2137, 2141, 2143
2378: 2377, 2381, 2383
2684: 2683, 2687, 2689
2708: 2707, 2711, 2713
2798: 2797, 2801, 2803
3164: 3163, 3167, 3169
3254: 3253, 3257, 3259
3458: 3457, 3461, 3463
3464: 3463, 3467, 3469
3848: 3847, 3851, 3853
4154: 4153, 4157, 4159
4514: 4513, 4517, 4519
4784: 4783, 4787, 4789
5228: 5227, 5231, 5233
5414: 5413, 5417, 5419
5438: 5437, 5441, 5443
5648: 5647, 5651, 5653
5654: 5653, 5657, 5659
5738: 5737, 5741, 5743

F#[edit]

This task uses Extensible Prime Generator (F#)

 
// Prime triplets: Nigel Galloway. May 18th., 2021
primes32()|>Seq.takeWhile((>)6000)|>Seq.filter(fun n->isPrime(n+4)&&isPrime(n+6))|>Seq.iter((+)1>>printf "%d "); printfn ""
 
Output:
8 14 38 68 98 104 194 224 278 308 458 614 824 854 878 1088 1298 1424 1448 1484 1664 1694 1784 1868 1874 1994 2084 2138 2378 2684 2708 2798 3164 3254 3458 3464 3848 4154 4514 4784 5228 5414 5438 5648 5654 5738

Factor[edit]

Works with: Factor version 0.99 2021-02-05
USING: combinators formatting grouping kernel math math.primes
math.statistics sequences ;
 
: 4,2-gaps ( upto -- seq )
4 + primes-upto 3 <clumps>
[ differences { 4 2 } sequence= ] filter ;
 
: triplet. ( 1 n 2 3 -- )
"..., %4d, [%4d], __, __, %4d, __, %4d, ...\n" printf ;
 
6000 4,2-gaps [ first3 [ dup 1 + ] 2dip triplet. ] each
Output:
...,    7, [   8], __, __,   11, __,   13, ...
...,   13, [  14], __, __,   17, __,   19, ...
...,   37, [  38], __, __,   41, __,   43, ...
...,   67, [  68], __, __,   71, __,   73, ...
...,   97, [  98], __, __,  101, __,  103, ...
...,  103, [ 104], __, __,  107, __,  109, ...
...,  193, [ 194], __, __,  197, __,  199, ...
...,  223, [ 224], __, __,  227, __,  229, ...
...,  277, [ 278], __, __,  281, __,  283, ...
...,  307, [ 308], __, __,  311, __,  313, ...
...,  457, [ 458], __, __,  461, __,  463, ...
...,  613, [ 614], __, __,  617, __,  619, ...
...,  823, [ 824], __, __,  827, __,  829, ...
...,  853, [ 854], __, __,  857, __,  859, ...
...,  877, [ 878], __, __,  881, __,  883, ...
..., 1087, [1088], __, __, 1091, __, 1093, ...
..., 1297, [1298], __, __, 1301, __, 1303, ...
..., 1423, [1424], __, __, 1427, __, 1429, ...
..., 1447, [1448], __, __, 1451, __, 1453, ...
..., 1483, [1484], __, __, 1487, __, 1489, ...
..., 1663, [1664], __, __, 1667, __, 1669, ...
..., 1693, [1694], __, __, 1697, __, 1699, ...
..., 1783, [1784], __, __, 1787, __, 1789, ...
..., 1867, [1868], __, __, 1871, __, 1873, ...
..., 1873, [1874], __, __, 1877, __, 1879, ...
..., 1993, [1994], __, __, 1997, __, 1999, ...
..., 2083, [2084], __, __, 2087, __, 2089, ...
..., 2137, [2138], __, __, 2141, __, 2143, ...
..., 2377, [2378], __, __, 2381, __, 2383, ...
..., 2683, [2684], __, __, 2687, __, 2689, ...
..., 2707, [2708], __, __, 2711, __, 2713, ...
..., 2797, [2798], __, __, 2801, __, 2803, ...
..., 3163, [3164], __, __, 3167, __, 3169, ...
..., 3253, [3254], __, __, 3257, __, 3259, ...
..., 3457, [3458], __, __, 3461, __, 3463, ...
..., 3463, [3464], __, __, 3467, __, 3469, ...
..., 3847, [3848], __, __, 3851, __, 3853, ...
..., 4153, [4154], __, __, 4157, __, 4159, ...
..., 4513, [4514], __, __, 4517, __, 4519, ...
..., 4783, [4784], __, __, 4787, __, 4789, ...
..., 5227, [5228], __, __, 5231, __, 5233, ...
..., 5413, [5414], __, __, 5417, __, 5419, ...
..., 5437, [5438], __, __, 5441, __, 5443, ...
..., 5647, [5648], __, __, 5651, __, 5653, ...
..., 5653, [5654], __, __, 5657, __, 5659, ...
..., 5737, [5738], __, __, 5741, __, 5743, ...

Forth[edit]

Works with: Gforth
: prime? ( n -- ? ) here + [email protected] 0= ;
: notprime! ( n -- ) here + 1 swap c! ;
 
: prime_sieve { n -- }
here n erase
0 notprime!
1 notprime!
n 4 > if
n 4 do i notprime! 2 +loop
then
3
begin
dup dup * n <
while
dup prime? if
n over dup * do
i notprime!
dup 2* +loop
then
2 +
repeat
drop ;
 
: main { n -- }
." N N-1 N+3 N+5" cr
n prime_sieve
0
n 1 do
i 1- prime? if
i 3 + prime? if
i 5 + prime? if
i 4 .r ." :"
i 1- 6 .r
i 3 + 6 .r
i 5 + 6 .r cr
1+
then
then
then
loop
cr ." Count: " . cr ;
 
6000 main
bye
Output:
   N    N-1   N+3   N+5
   8:     7    11    13
  14:    13    17    19
  38:    37    41    43
  68:    67    71    73
  98:    97   101   103
 104:   103   107   109
 194:   193   197   199
 224:   223   227   229
 278:   277   281   283
 308:   307   311   313
 458:   457   461   463
 614:   613   617   619
 824:   823   827   829
 854:   853   857   859
 878:   877   881   883
1088:  1087  1091  1093
1298:  1297  1301  1303
1424:  1423  1427  1429
1448:  1447  1451  1453
1484:  1483  1487  1489
1664:  1663  1667  1669
1694:  1693  1697  1699
1784:  1783  1787  1789
1868:  1867  1871  1873
1874:  1873  1877  1879
1994:  1993  1997  1999
2084:  2083  2087  2089
2138:  2137  2141  2143
2378:  2377  2381  2383
2684:  2683  2687  2689
2708:  2707  2711  2713
2798:  2797  2801  2803
3164:  3163  3167  3169
3254:  3253  3257  3259
3458:  3457  3461  3463
3464:  3463  3467  3469
3848:  3847  3851  3853
4154:  4153  4157  4159
4514:  4513  4517  4519
4784:  4783  4787  4789
5228:  5227  5231  5233
5414:  5413  5417  5419
5438:  5437  5441  5443
5648:  5647  5651  5653
5654:  5653  5657  5659
5738:  5737  5741  5743

Count: 46 

Go[edit]

Translation of: Wren
Library: Go-rcu
package main
 
import (
"fmt"
"rcu"
)
 
func main() {
c := rcu.PrimeSieve(6003, false)
var numbers []int
fmt.Println("Numbers n < 6000 where: n - 1, n + 3, n + 5 are all primes:")
for n := 4; n < 6000; n += 2 {
if !c[n-1] && !c[n+3] && !c[n+5] {
numbers = append(numbers, n)
}
}
for _, n := range numbers {
fmt.Printf("%6s => ", rcu.Commatize(n))
for _, p := range []int{n - 1, n + 3, n + 5} {
fmt.Printf("%6s ", rcu.Commatize(p))
}
fmt.Println()
}
fmt.Printf("\n%d such numbers found.\n", len(numbers))
}
Output:
Numbers n < 6000 where: n - 1, n + 3, n + 5 are all primes:
     8  =>      7     11     13 
    14  =>     13     17     19 
    38  =>     37     41     43 
    68  =>     67     71     73 
    98  =>     97    101    103 
   104  =>    103    107    109 
   194  =>    193    197    199 
   224  =>    223    227    229 
   278  =>    277    281    283 
   308  =>    307    311    313 
   458  =>    457    461    463 
   614  =>    613    617    619 
   824  =>    823    827    829 
   854  =>    853    857    859 
   878  =>    877    881    883 
 1,088  =>  1,087  1,091  1,093 
 1,298  =>  1,297  1,301  1,303 
 1,424  =>  1,423  1,427  1,429 
 1,448  =>  1,447  1,451  1,453 
 1,484  =>  1,483  1,487  1,489 
 1,664  =>  1,663  1,667  1,669 
 1,694  =>  1,693  1,697  1,699 
 1,784  =>  1,783  1,787  1,789 
 1,868  =>  1,867  1,871  1,873 
 1,874  =>  1,873  1,877  1,879 
 1,994  =>  1,993  1,997  1,999 
 2,084  =>  2,083  2,087  2,089 
 2,138  =>  2,137  2,141  2,143 
 2,378  =>  2,377  2,381  2,383 
 2,684  =>  2,683  2,687  2,689 
 2,708  =>  2,707  2,711  2,713 
 2,798  =>  2,797  2,801  2,803 
 3,164  =>  3,163  3,167  3,169 
 3,254  =>  3,253  3,257  3,259 
 3,458  =>  3,457  3,461  3,463 
 3,464  =>  3,463  3,467  3,469 
 3,848  =>  3,847  3,851  3,853 
 4,154  =>  4,153  4,157  4,159 
 4,514  =>  4,513  4,517  4,519 
 4,784  =>  4,783  4,787  4,789 
 5,228  =>  5,227  5,231  5,233 
 5,414  =>  5,413  5,417  5,419 
 5,438  =>  5,437  5,441  5,443 
 5,648  =>  5,647  5,651  5,653 
 5,654  =>  5,653  5,657  5,659 
 5,738  =>  5,737  5,741  5,743 

46 such numbers found.

J[edit]

triplet=: (1 *./@p: _1 3 5+])"0
echo (0 _1 3 5+])"0 (triplet#]) i.6000
exit ''
Output:
   8    7   11   13
  14   13   17   19
  38   37   41   43
  68   67   71   73
  98   97  101  103
 104  103  107  109
 194  193  197  199
 224  223  227  229
 278  277  281  283
 308  307  311  313
 458  457  461  463
 614  613  617  619
 824  823  827  829
 854  853  857  859
 878  877  881  883
1088 1087 1091 1093
1298 1297 1301 1303
1424 1423 1427 1429
1448 1447 1451 1453
1484 1483 1487 1489
1664 1663 1667 1669
1694 1693 1697 1699
1784 1783 1787 1789
1868 1867 1871 1873
1874 1873 1877 1879
1994 1993 1997 1999
2084 2083 2087 2089
2138 2137 2141 2143
2378 2377 2381 2383
2684 2683 2687 2689
2708 2707 2711 2713
2798 2797 2801 2803
3164 3163 3167 3169
3254 3253 3257 3259
3458 3457 3461 3463
3464 3463 3467 3469
3848 3847 3851 3853
4154 4153 4157 4159
4514 4513 4517 4519
4784 4783 4787 4789
5228 5227 5231 5233
5414 5413 5417 5419
5438 5437 5441 5443
5648 5647 5651 5653
5654 5653 5657 5659
5738 5737 5741 5743

Julia[edit]

using Primes
 
makesprimetriplet(n) = all(isprime, [n - 1, n + 3, n + 5])
println(" N Prime Triplet\n--------------------------")
foreach(n -> println(rpad(n, 6), [n - 1, n + 3, n + 5]), filter(makesprimetriplet, 2:6005))
 
Output:
 N       Prime Triplet
--------------------------
8     [7, 11, 13]
14    [13, 17, 19]
38    [37, 41, 43]
68    [67, 71, 73]
98    [97, 101, 103]
104   [103, 107, 109]
194   [193, 196, 199]
224   [223, 227, 229]
278   [277, 281, 283]
308   [307, 311, 313]
458   [457, 461, 463]
614   [613, 617, 619]
824   [823, 827, 829]
854   [853, 857, 859]
878   [877, 881, 883]
1088  [1087, 1091, 1093]
1298  [1297, 1301, 1303]
1424  [1423, 1427, 1429]
1448  [1447, 1451, 1453]
1484  [1483, 1487, 1489]
1664  [1663, 1667, 1669]
1694  [1693, 1697, 1699]
1784  [1783, 1787, 1789]
1868  [1867, 1871, 1873]
1874  [1873, 1877, 1879]
1994  [1993, 1997, 1999]
2084  [2083, 2087, 2089]
2138  [2137, 2141, 2143]
2378  [2377, 2381, 2383]
2684  [2683, 2687, 2689]
2708  [2707, 2711, 2713]
2798  [2797, 2801, 2803]
3164  [3163, 3167, 3169]
3254  [3253, 3257, 3259]
3458  [3457, 3461, 3463]
3464  [3463, 3467, 3469]
3848  [3847, 3851, 3853]
4154  [4153, 4157, 4159]
4514  [4513, 4517, 4519]
4784  [4783, 4787, 4789]
5228  [5227, 5231, 5233]
5414  [5413, 5417, 5419]
5438  [5437, 5441, 5443]
5648  [5647, 5651, 5653]
5654  [5653, 5657, 5659]
5738  [5737, 5741, 5743]

MAD[edit]

            NORMAL MODE IS INTEGER
BOOLEAN PRIME
DIMENSION PRIME(6005)
LIMIT = 6000
 
PRIME(0) = 0B
PRIME(1) = 0B
THROUGH SET, FOR I=2, 1, I.G.LIMIT+5
SET PRIME(I) = 1B
LAST = SQRT.(LIMIT+5)
THROUGH SIEVE, FOR I=2, 1, I.G.LAST
WHENEVER PRIME(I)
THROUGH UNSET, FOR J=I*2, I, J.G.LIMIT+5
UNSET PRIME(J) = 0B
END OF CONDITIONAL
SIEVE CONTINUE
 
THROUGH TEST, FOR I=2, 1, I.G.LIMIT
WHENEVER PRIME(I-1).AND.PRIME(I+3).AND.PRIME(I+5)
PRINT FORMAT FMT, I, I-1, I+3, I+5
END OF CONDITIONAL
TEST CONTINUE
 
VECTOR VALUES FMT = $I4,3H =,3(I5)*$
END OF PROGRAM
Output:
   8 =    7   11   13
  14 =   13   17   19
  38 =   37   41   43
  68 =   67   71   73
  98 =   97  101  103
 104 =  103  107  109
 194 =  193  197  199
 224 =  223  227  229
 278 =  277  281  283
 308 =  307  311  313
 458 =  457  461  463
 614 =  613  617  619
 824 =  823  827  829
 854 =  853  857  859
 878 =  877  881  883
1088 = 1087 1091 1093
1298 = 1297 1301 1303
1424 = 1423 1427 1429
1448 = 1447 1451 1453
1484 = 1483 1487 1489
1664 = 1663 1667 1669
1694 = 1693 1697 1699
1784 = 1783 1787 1789
1868 = 1867 1871 1873
1874 = 1873 1877 1879
1994 = 1993 1997 1999
2084 = 2083 2087 2089
2138 = 2137 2141 2143
2378 = 2377 2381 2383
2684 = 2683 2687 2689
2708 = 2707 2711 2713
2798 = 2797 2801 2803
3164 = 3163 3167 3169
3254 = 3253 3257 3259
3458 = 3457 3461 3463
3464 = 3463 3467 3469
3848 = 3847 3851 3853
4154 = 4153 4157 4159
4514 = 4513 4517 4519
4784 = 4783 4787 4789
5228 = 5227 5231 5233
5414 = 5413 5417 5419
5438 = 5437 5441 5443
5648 = 5647 5651 5653
5654 = 5653 5657 5659
5738 = 5737 5741 5743

Nim[edit]

import strformat
 
const
N = 5999
Max = 6003 # 5998 + 5.
 
# Sieve of Erathosthenes: false (default) is composite.
var composite: array[3..Max, bool] # Ignore 2 as all primes should be odd.
var n = 3
while true:
let n2 = n * n
if n2 > Max: break
if not composite[n]:
for k in countup(n2, Max, 2 * n):
composite[k] = true
inc n, 2
 
template isPrime(n: int): bool = not composite[n]
 
echo " n n-1 n+3 n+5"
var count = 0
for n in countup(4, N, 2):
if (n - 1).isPrime and (n + 3).isPrime and (n + 5).isPrime:
echo &"{n:4}: {n-1:4} {n+3:4} {n+5:4}"
inc count
 
echo &"\nFound {count} triplets for n < {N+1}."
Output:
   n   n-1  n+3  n+5
   8:    7   11   13
  14:   13   17   19
  38:   37   41   43
  68:   67   71   73
  98:   97  101  103
 104:  103  107  109
 194:  193  197  199
 224:  223  227  229
 278:  277  281  283
 308:  307  311  313
 458:  457  461  463
 614:  613  617  619
 824:  823  827  829
 854:  853  857  859
 878:  877  881  883
1088: 1087 1091 1093
1298: 1297 1301 1303
1424: 1423 1427 1429
1448: 1447 1451 1453
1484: 1483 1487 1489
1664: 1663 1667 1669
1694: 1693 1697 1699
1784: 1783 1787 1789
1868: 1867 1871 1873
1874: 1873 1877 1879
1994: 1993 1997 1999
2084: 2083 2087 2089
2138: 2137 2141 2143
2378: 2377 2381 2383
2684: 2683 2687 2689
2708: 2707 2711 2713
2798: 2797 2801 2803
3164: 3163 3167 3169
3254: 3253 3257 3259
3458: 3457 3461 3463
3464: 3463 3467 3469
3848: 3847 3851 3853
4154: 4153 4157 4159
4514: 4513 4517 4519
4784: 4783 4787 4789
5228: 5227 5231 5233
5414: 5413 5417 5419
5438: 5437 5441 5443
5648: 5647 5651 5653
5654: 5653 5657 5659
5738: 5737 5741 5743

Found 46 triplets for n < 6000.

Perl[edit]

#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Triplet_of_three_numbers
use warnings;
 
my %cache;
sub isprime { $cache{$_[0]} //= (1 x $_[0]) =~ /^(11+)\1+$/ ? 0 : 1 }
 
for ( 3 .. 6000 )
{
$_ & 1 and isprime($_+6) and isprime($_+4) and isprime($_) and
printf "%6d" x 4 . "\n", $_ + 1, $_, $_ + 4, $_ + 6;
}
Output:
     8     7    11    13
    14    13    17    19
    38    37    41    43
    68    67    71    73
    98    97   101   103
   104   103   107   109
   194   193   197   199
   224   223   227   229
   278   277   281   283
   308   307   311   313
   458   457   461   463
   614   613   617   619
   824   823   827   829
   854   853   857   859
   878   877   881   883
  1088  1087  1091  1093
  1298  1297  1301  1303
  1424  1423  1427  1429
  1448  1447  1451  1453
  1484  1483  1487  1489
  1664  1663  1667  1669
  1694  1693  1697  1699
  1784  1783  1787  1789
  1868  1867  1871  1873
  1874  1873  1877  1879
  1994  1993  1997  1999
  2084  2083  2087  2089
  2138  2137  2141  2143
  2378  2377  2381  2383
  2684  2683  2687  2689
  2708  2707  2711  2713
  2798  2797  2801  2803
  3164  3163  3167  3169
  3254  3253  3257  3259
  3458  3457  3461  3463
  3464  3463  3467  3469
  3848  3847  3851  3853
  4154  4153  4157  4159
  4514  4513  4517  4519
  4784  4783  4787  4789
  5228  5227  5231  5233
  5414  5413  5417  5419
  5438  5437  5441  5443
  5648  5647  5651  5653
  5654  5653  5657  5659
  5738  5737  5741  5743

Phix[edit]

function trio(integer n) return sum(apply({n-1,n+3,n+5},is_prime))=3 end function
sequence res = filter(tagset(6000),trio)
printf(1,"%d found: %V\n",{length(res),shorten(res,"",5)})
Output:

(assumes you can add {-1,3,5} to each number in your head easily enough)

46 found: {8,14,38,68,98,"...",5414,5438,5648,5654,5738}

PL/M[edit]

100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9, S); END PRINT;
 
DECLARE LIMIT LITERALLY '6000';
 
PRINT$NUMBER: PROCEDURE (N);
DECLARE S (6) BYTE INITIAL ('.....$');
DECLARE (N, P) ADDRESS, C BASED P BYTE;
P = .S(5);
DIGIT:
P = P-1;
C = N MOD 10 + '0';
N = N/10;
IF N>0 THEN GO TO DIGIT;
CALL PRINT(P);
END PRINT$NUMBER;
 
SIEVE: PROCEDURE (PX, N);
DECLARE (PX, N, P BASED PX) ADDRESS;
DECLARE (I, J) ADDRESS;
P(0) = 0;
P(1) = 0;
DO I=2 TO N;
P(I) = 1;
END;
DO I=2 TO N/2;
IF P(I) THEN
DO J=I*2 TO N BY I;
P(J) = 0;
END;
END;
END SIEVE;
 
IS$TRIPLE: PROCEDURE (PX, N) BYTE;
DECLARE (PX, N, P BASED PX) ADDRESS;
IF N < 2 THEN RETURN 0;
RETURN P(N-1) AND P(N+3) AND P(N+5);
END IS$TRIPLE;
 
PRINT$TRIPLE: PROCEDURE (N);
DECLARE COMMA DATA (', $');
DECLARE N ADDRESS;
CALL PRINT$NUMBER(N);
CALL PRINT(.': $');
CALL PRINT$NUMBER(N-1);
CALL PRINT(.COMMA);
CALL PRINT$NUMBER(N+3);
CALL PRINT(.COMMA);
CALL PRINT$NUMBER(N+5);
CALL PRINT(.(13,10,'$'));
END PRINT$TRIPLE;
 
DECLARE I ADDRESS;
CALL SIEVE(.MEMORY, LIMIT+5);
DO I=2 TO LIMIT;
IF IS$TRIPLE(.MEMORY, I) THEN CALL PRINT$TRIPLE(I);
END;
CALL EXIT;
EOF
Output:
8: 7, 11, 13
14: 13, 17, 19
38: 37, 41, 43
68: 67, 71, 73
98: 97, 101, 103
104: 103, 107, 109
194: 193, 197, 199
224: 223, 227, 229
278: 277, 281, 283
308: 307, 311, 313
458: 457, 461, 463
614: 613, 617, 619
824: 823, 827, 829
854: 853, 857, 859
878: 877, 881, 883
1088: 1087, 1091, 1093
1298: 1297, 1301, 1303
1424: 1423, 1427, 1429
1448: 1447, 1451, 1453
1484: 1483, 1487, 1489
1664: 1663, 1667, 1669
1694: 1693, 1697, 1699
1784: 1783, 1787, 1789
1868: 1867, 1871, 1873
1874: 1873, 1877, 1879
1994: 1993, 1997, 1999
2084: 2083, 2087, 2089
2138: 2137, 2141, 2143
2378: 2377, 2381, 2383
2684: 2683, 2687, 2689
2708: 2707, 2711, 2713
2798: 2797, 2801, 2803
3164: 3163, 3167, 3169
3254: 3253, 3257, 3259
3458: 3457, 3461, 3463
3464: 3463, 3467, 3469
3848: 3847, 3851, 3853
4154: 4153, 4157, 4159
4514: 4513, 4517, 4519
4784: 4783, 4787, 4789
5228: 5227, 5231, 5233
5414: 5413, 5417, 5419
5438: 5437, 5441, 5443
5648: 5647, 5651, 5653
5654: 5653, 5657, 5659
5738: 5737, 5741, 5743

Quackery[edit]

 [ 1 swap times [ i 1+ * ] ] is !     ( n --> n )
 
[ dup 2 < iff
[ drop false ] done
dup 1 - ! 1+
swap mod 0 = ] is prime ( n --> b )
 
[] 3000 times
[ i^ 2 *
dup 1 - prime iff
[ dup 3 + prime iff
[ dup 5 + prime iff
join else drop ]
else drop ]
else drop ]
echo
Output:
[ 8 14 38 68 98 104 194 224 278 308 458 614 824 854 878 1088 1298 1424 1448 1484 1664 1694 1784 1868 1874 1994 2084 2138 2378 2684 2708 2798 3164 3254 3458 3464 3848 4154 4514 4784 5228 5414 5438 5648 5654 5738 ]


Raku[edit]

A weird combination of Cousin primes and Twin primes that are siblings, but known by their neighbor.... I shall dub these Alabama primes.

say "{.[0]+1}: ",$_ for grep *.all.is-prime, ^6000 .race.map: { $_-1, $_+3, $_+5 };
Output:
8: (7 11 13)
14: (13 17 19)
38: (37 41 43)
68: (67 71 73)
98: (97 101 103)
104: (103 107 109)
194: (193 197 199)
224: (223 227 229)
278: (277 281 283)
308: (307 311 313)
458: (457 461 463)
614: (613 617 619)
824: (823 827 829)
854: (853 857 859)
878: (877 881 883)
1088: (1087 1091 1093)
1298: (1297 1301 1303)
1424: (1423 1427 1429)
1448: (1447 1451 1453)
1484: (1483 1487 1489)
1664: (1663 1667 1669)
1694: (1693 1697 1699)
1784: (1783 1787 1789)
1868: (1867 1871 1873)
1874: (1873 1877 1879)
1994: (1993 1997 1999)
2084: (2083 2087 2089)
2138: (2137 2141 2143)
2378: (2377 2381 2383)
2684: (2683 2687 2689)
2708: (2707 2711 2713)
2798: (2797 2801 2803)
3164: (3163 3167 3169)
3254: (3253 3257 3259)
3458: (3457 3461 3463)
3464: (3463 3467 3469)
3848: (3847 3851 3853)
4154: (4153 4157 4159)
4514: (4513 4517 4519)
4784: (4783 4787 4789)
5228: (5227 5231 5233)
5414: (5413 5417 5419)
5438: (5437 5441 5443)
5648: (5647 5651 5653)
5654: (5653 5657 5659)
5738: (5737 5741 5743)

REXX[edit]

/*REXX pgm finds prime triplets (Alabama primes) such that  P, P-1, and P+2  are primes.*/
parse arg hi . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 6000 /*Not specified? Then use the default.*/
call genP /*build array of semaphores for primes.*/
w= length( commas(hi) ) /*the width of the largest number. */
ow= 70; pad= left('', w + 1) /*the width of the data column. */
@primTrip= ' prime triplets such that N-1, N+3, N+5 are prime, N < ' commas(hi)
say ' N │'center(@primTrip, 1 + (ow+1) ) /*display the title for the output grid*/
say '───────┼'center("" , 1 + (ow+1), '─') /* " " header " " " " */
found= 0 /*initialize # of prime triplets. */
do j=1 for hi-1 /*find some prime triplets < HI. */
if \isPrime(j-1) | \isPrime(j+3) | \isPrime(j+5) then iterate /*¬ prime? */
found= found + 1 /*bump the number of prime triplets. */
say center(commas(j), 7)'│' pad "(N-1)=" right( commas(j-1), w) ,
pad '(N+3)=' right( commas(j+3), w) ,
pad "(N+5)=" right( commas(j+5), w)
end /*j*/
 
say '───────┴'center("" , 1 + (ow+1), '─') /*display foot header for output grid. */
say
say 'Found ' commas(found) @primTrip
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
isPrime: parse arg ?; return !.?
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: @.1=2; @.2=3; @.3=5; @.4=7 /*define some low primes. */
 !.=0;  !.2=1;  !.3=1;  !.5=1;  !.7=1 /* " " " " semaphores. */
#=4; s.#= @.# **2 /*number of primes so far; prime². */
do [email protected].#+2 by 2 to hi /*find odd primes where P < hi. */
parse var j '' -1 _; if _==5 then iterate /*J divisible by 5? (right dig)*/
if j// 3==0 then iterate /*" " " 3? */
do k=4 while s.k<=j /* [↓] divide by the known odd primes.*/
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j;  !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return
output   when using the default inputs:
   N   │   prime triplets such that  N-1,  N+3,  N+5  are prime,  N  <  6,000
───────┼────────────────────────────────────────────────────────────────────────
   8   │        (N-1)=     7        (N+3)=    11        (N+5)=    13
  14   │        (N-1)=    13        (N+3)=    17        (N+5)=    19
  38   │        (N-1)=    37        (N+3)=    41        (N+5)=    43
  68   │        (N-1)=    67        (N+3)=    71        (N+5)=    73
  98   │        (N-1)=    97        (N+3)=   101        (N+5)=   103
  104  │        (N-1)=   103        (N+3)=   107        (N+5)=   109
  194  │        (N-1)=   193        (N+3)=   197        (N+5)=   199
  224  │        (N-1)=   223        (N+3)=   227        (N+5)=   229
  278  │        (N-1)=   277        (N+3)=   281        (N+5)=   283
  308  │        (N-1)=   307        (N+3)=   311        (N+5)=   313
  458  │        (N-1)=   457        (N+3)=   461        (N+5)=   463
  614  │        (N-1)=   613        (N+3)=   617        (N+5)=   619
  824  │        (N-1)=   823        (N+3)=   827        (N+5)=   829
  854  │        (N-1)=   853        (N+3)=   857        (N+5)=   859
  878  │        (N-1)=   877        (N+3)=   881        (N+5)=   883
 1,088 │        (N-1)= 1,087        (N+3)= 1,091        (N+5)= 1,093
 1,298 │        (N-1)= 1,297        (N+3)= 1,301        (N+5)= 1,303
 1,424 │        (N-1)= 1,423        (N+3)= 1,427        (N+5)= 1,429
 1,448 │        (N-1)= 1,447        (N+3)= 1,451        (N+5)= 1,453
 1,484 │        (N-1)= 1,483        (N+3)= 1,487        (N+5)= 1,489
 1,664 │        (N-1)= 1,663        (N+3)= 1,667        (N+5)= 1,669
 1,694 │        (N-1)= 1,693        (N+3)= 1,697        (N+5)= 1,699
 1,784 │        (N-1)= 1,783        (N+3)= 1,787        (N+5)= 1,789
 1,868 │        (N-1)= 1,867        (N+3)= 1,871        (N+5)= 1,873
 1,874 │        (N-1)= 1,873        (N+3)= 1,877        (N+5)= 1,879
 1,994 │        (N-1)= 1,993        (N+3)= 1,997        (N+5)= 1,999
 2,084 │        (N-1)= 2,083        (N+3)= 2,087        (N+5)= 2,089
 2,138 │        (N-1)= 2,137        (N+3)= 2,141        (N+5)= 2,143
 2,378 │        (N-1)= 2,377        (N+3)= 2,381        (N+5)= 2,383
 2,684 │        (N-1)= 2,683        (N+3)= 2,687        (N+5)= 2,689
 2,708 │        (N-1)= 2,707        (N+3)= 2,711        (N+5)= 2,713
 2,798 │        (N-1)= 2,797        (N+3)= 2,801        (N+5)= 2,803
 3,164 │        (N-1)= 3,163        (N+3)= 3,167        (N+5)= 3,169
 3,254 │        (N-1)= 3,253        (N+3)= 3,257        (N+5)= 3,259
 3,458 │        (N-1)= 3,457        (N+3)= 3,461        (N+5)= 3,463
 3,464 │        (N-1)= 3,463        (N+3)= 3,467        (N+5)= 3,469
 3,848 │        (N-1)= 3,847        (N+3)= 3,851        (N+5)= 3,853
 4,154 │        (N-1)= 4,153        (N+3)= 4,157        (N+5)= 4,159
 4,514 │        (N-1)= 4,513        (N+3)= 4,517        (N+5)= 4,519
 4,784 │        (N-1)= 4,783        (N+3)= 4,787        (N+5)= 4,789
 5,228 │        (N-1)= 5,227        (N+3)= 5,231        (N+5)= 5,233
 5,414 │        (N-1)= 5,413        (N+3)= 5,417        (N+5)= 5,419
 5,438 │        (N-1)= 5,437        (N+3)= 5,441        (N+5)= 5,443
 5,648 │        (N-1)= 5,647        (N+3)= 5,651        (N+5)= 5,653
 5,654 │        (N-1)= 5,653        (N+3)= 5,657        (N+5)= 5,659
 5,738 │        (N-1)= 5,737        (N+3)= 5,741        (N+5)= 5,743
───────┴────────────────────────────────────────────────────────────────────────

Found  46  prime triplets such that  N-1,  N+3,  N+5  are prime,  N  <  6,000

Ring[edit]

 
load "stdlib.ring"
see "working..." + nl
see "n prime triplet" + nl
see "----------------" + nl
row = 0
 
limit = 6000
 
for n = 2 to limit-2
bool1 = isprime(n-1)
bool2 = isprime(n+3)
bool3 = isprime(n+5)
bool = bool1 and bool2 and bool3
if bool
row = row + 1
see "" + n + ": (" + (n-1) + " " + (n+3) + " " + (n+5) + ")" + nl
ok
next
 
see "Found " + row + " prime triplets" + nl
see "done..." + nl
 
Output:
working...
n  prime triplet
----------------
8: (7 11 13)
14: (13 17 19)
38: (37 41 43)
68: (67 71 73)
98: (97 101 103)
104: (103 107 109)
194: (193 197 199)
224: (223 227 229)
278: (277 281 283)
308: (307 311 313)
458: (457 461 463)
614: (613 617 619)
824: (823 827 829)
854: (853 857 859)
878: (877 881 883)
1088: (1087 1091 1093)
1298: (1297 1301 1303)
1424: (1423 1427 1429)
1448: (1447 1451 1453)
1484: (1483 1487 1489)
1664: (1663 1667 1669)
1694: (1693 1697 1699)
1784: (1783 1787 1789)
1868: (1867 1871 1873)
1874: (1873 1877 1879)
1994: (1993 1997 1999)
2084: (2083 2087 2089)
2138: (2137 2141 2143)
2378: (2377 2381 2383)
2684: (2683 2687 2689)
2708: (2707 2711 2713)
2798: (2797 2801 2803)
3164: (3163 3167 3169)
3254: (3253 3257 3259)
3458: (3457 3461 3463)
3464: (3463 3467 3469)
3848: (3847 3851 3853)
4154: (4153 4157 4159)
4514: (4513 4517 4519)
4784: (4783 4787 4789)
5228: (5227 5231 5233)
5414: (5413 5417 5419)
5438: (5437 5441 5443)
5648: (5647 5651 5653)
5654: (5653 5657 5659)
5738: (5737 5741 5743)
Found 46 prime triplets
done...

Wren[edit]

Library: Wren-math
Library: Wren-fmt
import "/math" for Int
import "/fmt" for Fmt
 
var c = Int.primeSieve(6003, false)
var numbers = []
System.print("Numbers n < 6000 where: n - 1, n + 3, n + 5 are all primes:")
var n = 4
while (n < 6000) {
if (!c[n-1] && !c[n+3] && !c[n+5]) numbers.add(n)
n = n + 2
}
for (n in numbers) Fmt.print("$,6d => $,6d", n, [n-1, n+3, n+5])
System.print("\nFound %(numbers.count) such numbers.")
Output:
Numbers n < 6000 where: n - 1, n + 3, n + 5 are all primes:
     8  =>      7     11     13
    14  =>     13     17     19
    38  =>     37     41     43
    68  =>     67     71     73
    98  =>     97    101    103
   104  =>    103    107    109
   194  =>    193    197    199
   224  =>    223    227    229
   278  =>    277    281    283
   308  =>    307    311    313
   458  =>    457    461    463
   614  =>    613    617    619
   824  =>    823    827    829
   854  =>    853    857    859
   878  =>    877    881    883
 1,088  =>  1,087  1,091  1,093
 1,298  =>  1,297  1,301  1,303
 1,424  =>  1,423  1,427  1,429
 1,448  =>  1,447  1,451  1,453
 1,484  =>  1,483  1,487  1,489
 1,664  =>  1,663  1,667  1,669
 1,694  =>  1,693  1,697  1,699
 1,784  =>  1,783  1,787  1,789
 1,868  =>  1,867  1,871  1,873
 1,874  =>  1,873  1,877  1,879
 1,994  =>  1,993  1,997  1,999
 2,084  =>  2,083  2,087  2,089
 2,138  =>  2,137  2,141  2,143
 2,378  =>  2,377  2,381  2,383
 2,684  =>  2,683  2,687  2,689
 2,708  =>  2,707  2,711  2,713
 2,798  =>  2,797  2,801  2,803
 3,164  =>  3,163  3,167  3,169
 3,254  =>  3,253  3,257  3,259
 3,458  =>  3,457  3,461  3,463
 3,464  =>  3,463  3,467  3,469
 3,848  =>  3,847  3,851  3,853
 4,154  =>  4,153  4,157  4,159
 4,514  =>  4,513  4,517  4,519
 4,784  =>  4,783  4,787  4,789
 5,228  =>  5,227  5,231  5,233
 5,414  =>  5,413  5,417  5,419
 5,438  =>  5,437  5,441  5,443
 5,648  =>  5,647  5,651  5,653
 5,654  =>  5,653  5,657  5,659
 5,738  =>  5,737  5,741  5,743

Found 46 such numbers.