Triplet of three numbers: Difference between revisions

m
m (added whitespace.)
 
(31 intermediate revisions by 24 users not shown)
Line 2:
 
;Task:
Numbers   '''n'''   such that the three numbers   '''n-1''',   '''n+3''',   and   '''n+5'''   are all prime,   where   '''n < 60006,000.'''
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V n = 6000
V p = [0B] * 6000
 
L(i) 2 .< Int(round(sqrt(n)))
I !p[i]
L(j) (i * 2 .< n).step(i)
p[j] = 1B
 
L(i) 3 .< n
I (p[i - 1] | p[i + 3] | p[i + 5])
L.continue
E
print(f:‘{i:4}: {i - 1:4} {i + 3:4} {i + 5:4}’)</syntaxhighlight>
 
{{out}}
<pre>
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
</pre>
 
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
<syntaxhighlight lang="action!">INCLUDE "H6:SIEVE.ACT"
 
PROC Main()
DEFINE MAX="5999"
BYTE ARRAY primes(MAX+1)
INT i,count=[0]
 
Put(125) PutE() ;clear the screen
Sieve(primes,MAX+1)
FOR i=3 TO MAX-5
DO
IF primes(i-1)=1 AND primes(i+3)=1 AND primes(i+5)=1 THEN
PrintF("(%I,%I,%I) ",i-1,i+3,i+5)
count==+1
FI
OD
PrintF("%E%EThere are %I triplets",count)
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Triplet_of_three_numbers.png Screenshot from Atari 8-bit computer]
<pre>
(7,11,13) (13,17,19) (37,41,43) (67,71,73) (97,101,103) (103,107,109) (193,197,199) (223,227,229) (277,281,283)
(307,311,313) (457,461,463) (613,617,619) (823,827,829) (853,857,859) (877,881,883) (1087,1091,1093)
(1297,1301,1303) (1423,1427,1429) (1447,1451,1453) (1483,1487,1489) (1663,1667,1669) (1693,1697,1699)
(1783,1787,1789) (1867,1871,1873) (1873,1877,1879) (1993,1997,1999) (2083,2087,2089) (2137,2141,2143)
(2377,2381,2383) (2683,2687,2689) (2707,2711,2713) (2797,2801,2803) (3163,3167,3169) (3253,3257,3259)
(3457,3461,3463) (3463,3467,3469) (3847,3851,3853) (4153,4157,4159) (4513,4517,4519) (4783,4787,4789)
(5227,5231,5233) (5413,5417,5419) (5437,5441,5443) (5647,5651,5653) (5653,5657,5659) (5737,5741,5743)
 
There are 46 triplets
</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_Io;
 
procedure Triplets is
 
Limit : constant := 5999;
Prime : array (1 .. Limit + 5) of Boolean := (others => True);
 
procedure Fill_Primes is
begin
Prime (1) := False;
for N in 2 .. Limit loop
if Prime (N) then
for I in 2 .. Positive'Last loop
exit when I * N not in Prime'Range;
Prime (I * N) := False;
end loop;
end if;
end loop;
end Fill_Primes;
 
function Is_Triplet (N : Natural) return Boolean is
begin
return
Prime (N - 1) and then
Prime (N + 3) and then
Prime (N + 5);
end Is_Triplet;
 
package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
use Ada.Text_Io, Natural_IO;
begin
Natural_Io.Default_Width := 5;
Fill_Primes;
 
for N in 2 .. Limit loop
if Is_Triplet (N) then
Put (N, Width => 4);
Put (":");
Put (N - 1);
Put (N + 3);
Put (N + 5);
New_Line;
end if;
end loop;
end Triplets;</syntaxhighlight>
{{out}}
<pre>
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
</pre>
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find numbers n where n-1, n+3 and n+5 are prime #
<syntaxhighlight lang="algol68">BEGIN # find numbers n where n-1, n+3 and n+5 are prime #
INT max number = 6000;
# sieve the primes up to maxthe maximum number for the task #
PR read "primes.incl.a68" PR
[ 1 : max number ]BOOL prime;
prime[ 1 ] := FALSE;BOOL prime[ 2= ] :=PRIMESIEVE TRUE6000;
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 );
Line 22 ⟶ 213:
# 2 is clearly not a member of the required numbers, so we start at 3 #
INT n count := 0;
FOR n FROM 3 TO maxUPB numberprime - 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 ), ")" ) );
Line 30 ⟶ 221:
OD;
print( ( newline, "Found ", TOSTRING n count, " triplets", newline ) )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 50 ⟶ 241:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">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]</langsyntaxhighlight>
 
{{out}}
Line 65 ⟶ 256:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f TRIPLET_OF_THREE_NUMBERS.AWK
BEGIN {
Line 92 ⟶ 283:
return(1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 147 ⟶ 338:
 
=={{header|BASIC}}==
<langsyntaxhighlight lang="basic">10 DEFINT A-Z: N=6000
20 DIM P(N+5)
30 FOR I=2 TO SQR(N)
Line 155 ⟶ 346:
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</langsyntaxhighlight>
{{out}}
<pre style='height:50ex'> 8: 7 11 13
Line 203 ⟶ 394:
5,654: 5,653 5,657 5,659
5,738: 5,737 5,741 5,743</pre>
 
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic256">
N = 6000
dim p(N+6)
 
for i = 2 to sqr(N)
if not p[i] then
for j = i*2 to N step i
p[j] = 1
next j
end if
next i
 
for i = 3 to N
if (p[i-1] or p[i+3] or p[i+5]) then
# en BASIC256 no exite un comando CONTINUE
else
print i; ": "; i-1; " "; i+3; " "; i+5
end if
next i
end
</syntaxhighlight>
{{out}}
<pre>
Similar a la entrada de FreeBASIC.
</pre>
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
manifest $( limit = 6000 $)
 
Line 231 ⟶ 451:
writef("%I4: %I4, %I4, %I4*N", i, i-1, i+3, i+5)
freevec(prime)
$)</langsyntaxhighlight>
{{out}}
<pre style='height:50ex'> 8: 7, 11, 13
Line 281 ⟶ 501:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 316 ⟶ 536:
free(p);
return 0;
}</langsyntaxhighlight>
{{out}}
<pre style='height:50ex'> 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</pre>
 
=={{header|C++}}==
{{trans|C}}
<syntaxhighlight lang="cpp">#include <iostream>
#include <vector>
 
constexpr unsigned int LIMIT = 6000;
 
std::vector<bool> primes(unsigned int limit) {
std::vector<bool> p(limit + 1, true);
unsigned int root = std::sqrt(limit);
 
p[0] = false;
p[1] = false;
 
for (size_t i = 2; i <= root; i++) {
if (p[i]) {
for (size_t j = 2 * i; j <= limit; j += i) {
p[j] = false;
}
}
}
 
return p;
}
 
bool triplet(const std::vector<bool> &p, unsigned int n) {
return n >= 2 && p[n - 1] && p[n + 3] && p[n + 5];
}
 
int main() {
std::vector<bool> p = primes(LIMIT);
 
for (size_t i = 2; i < LIMIT; i++) {
if (triplet(p, i)) {
printf("%4d: %4d, %4d, %4d\n", i, i - 1, i + 3, i + 5);
}
}
 
return 0;
}</syntaxhighlight>
{{out}}
<pre> 8: 7, 11, 13
14: 13, 17, 19
38: 37, 41, 43
Line 367 ⟶ 675:
=={{header|C#|CSharp}}==
How about some upper limits above 6000?
<langsyntaxhighlight lang="csharp">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() {
Line 388 ⟶ 696:
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); } }</langsyntaxhighlight>
{{out}}
<pre style='height:50ex'> "N": Prime Triplet Adjacent (to previous)
Line 444 ⟶ 752:
Up to 100,000,000 there are 55,556 prime triples, of which 686 were found to be adjacent.
</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">LIMIT = 6000
 
isqrt = proc (s: int) returns (int)
x0: int := s/2
if x0=0 then return(s) end
x1: int := (x0 + s/x0)/2
while x1 < x0 do
x0 := x1
x1 := (x0 + s/x0)/2
end
return(x0)
end isqrt
 
sieve = proc (n: int) returns (array[bool])
prime: array[bool] := array[bool]$fill(2,n-1,true)
for p: int in int$from_to(2,isqrt(n)) do
if prime[p] then
for c: int in int$from_to_by(p*p,n,p) do
prime[c] := false
end
end
end
return(prime)
end sieve
 
triplet = proc (n: int, prime: array[bool]) returns (bool)
return(prime[n-1] & prime[n+3] & prime[n+5])
except when bounds: return(false) end
end triplet
 
start_up = proc ()
po: stream := stream$primary_output()
prime: array[bool] := sieve(LIMIT)
for i: int in int$from_to(2,LIMIT) do
if triplet(i, prime) then
stream$putright(po, int$unparse(i), 4)
stream$puts(po, ": ")
stream$putright(po, int$unparse(i-1), 4)
stream$puts(po, ", ")
stream$putright(po, int$unparse(i+3), 4)
stream$puts(po, ", ")
stream$putright(po, int$unparse(i+5), 4)
stream$putl(po, "")
end
end
end start_up</syntaxhighlight>
{{out}}
<pre style='height:50ex;'> 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</pre>
 
=={{header|Comal}}==
<syntaxhighlight lang="comal">0010 lim#:=6000
0020 DIM prime#(lim#)
0030 FOR i#:=2 TO lim# DO prime#(i#):=TRUE
0040 FOR p#:=2 TO INT(SQR(lim#)) DO
0050 FOR c#:=p#^2 TO lim# STEP p# DO prime#(c#):=FALSE
0060 ENDFOR p#
0070 FOR i#:=2 TO lim#-5 DO
0080 IF prime#(i#-1) AND prime#(i#+3) AND prime#(i#+5) THEN
0090 PRINT USING "####: ####, ####, ####":i#,i#-1,i#+3,i#+5
0100 ENDIF
0110 ENDFOR i#
0120 END</syntaxhighlight>
{{out}}
<pre style='height:50ex;'> 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</pre>
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
const LIMIT := 6000;
Line 482 ⟶ 946:
end if;
i := i + 1;
end loop;</langsyntaxhighlight>
{{out}}
<pre style='height:50ex'>8: 7, 11, 13
Line 530 ⟶ 994:
5654: 5653, 5657, 5659
5738: 5737, 5741, 5743</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
Uses the [[Extensible_prime_generator#Delphi|Delphi Prime-Generator Object]]
 
<syntaxhighlight lang="Delphi">
 
procedure ShowTriplePrimes(Memo: TMemo);
var I: integer;
var Sieve: TPrimeSieve;
begin
Sieve:=TPrimeSieve.Create;
try
Sieve.Intialize(10000);
for I:=1 to 6000-1 do
begin
if Sieve.Flags[I-1] and
Sieve.Flags[I+3] and
Sieve.Flags[I+5] then
begin
Memo.Lines.Add(Format('%d: %d %d %d',[I,I-1,I+3,I+5]));
end;
end;
 
finally Sieve.Free; end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
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
 
Elapsed Time: 96.852 ms.
</pre>
 
=={{header|EasyLang}}==
{{trans|BASIC256}}
<syntaxhighlight>
n = 6000
len p[] n + 4
for i = 2 to sqrt len p[]
if p[i] = 0
for j = i * 2 step i to len p[]
p[j] = 1
.
.
.
for i = 3 to n - 1
if p[i - 1] = 0 and p[i + 3] = 0 and p[i + 5] = 0
print i & ": " & i - 1 & " " & i + 3 & " " & i + 5
.
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<langsyntaxhighlight lang="fsharp">
// 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 ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 543 ⟶ 1,107:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: combinators formatting grouping kernel math math.primes
math.statistics sequences ;
 
Line 553 ⟶ 1,117:
"..., %4d, [%4d], __, __, %4d, __, %4d, ...\n" printf ;
 
6000 4,2-gaps [ first3 [ dup 1 + ] 2dip triplet. ] each</langsyntaxhighlight>
{{out}}
<pre style="height:14em">
Line 606 ⟶ 1,170:
=={{header|Forth}}==
{{works with|Gforth}}
<langsyntaxhighlight lang="forth">: prime? ( n -- ? ) here + c@ 0= ;
: notprime! ( n -- ) here + 1 swap c! ;
 
Line 649 ⟶ 1,213:
 
6000 main
bye</langsyntaxhighlight>
 
{{out}}
Line 703 ⟶ 1,267:
Count: 46
</pre>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
Dim As Integer N = 6000
Dim As Integer p(N)
 
For i As Integer = 2 To Sqr(N)
If Not p(i) Then
For j As Integer = i * 2 To N Step i
p(j) = 1
Next j
End If
Next i
For i As Integer = 3 To N
If (p(i-1) Or p(i+3) Or p(i+5)) Then
Continue For
Else
Print Using "####,: ####, ####, ####,"; i; i-1; i+3; i+5
End If
Next i
Sleep
</syntaxhighlight>
<pre>
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
</pre>
 
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 731 ⟶ 1,367:
}
fmt.Printf("\n%d such numbers found.\n", len(numbers))
}</langsyntaxhighlight>
 
{{out}}
Line 787 ⟶ 1,423:
 
=={{header|J}}==
<langsyntaxhighlight lang="j">triplet=: (1 *./@p: _1 3 5+])"0
echo (0 _1 3 5+])"0 (triplet#]) i.6000
exit ''</langsyntaxhighlight>
{{out}}
<pre style='height:50ex'> 8 7 11 13
Line 837 ⟶ 1,473:
5654 5653 5657 5659
5738 5737 5741 5743</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
<syntaxhighlight lang="jq">def is_prime:
if . == 2 then true
else
2 < . and . % 2 == 1 and
(. as $in
| (($in + 1) | sqrt) as $m
| [false, 3] | until( .[0] or .[1] > $m; [$in % .[1] == 0, .[1] + 2])
| .[0]
| not)
end ;
 
range(3;6000) | select( all( .-1, .+3, .+5; is_prime))</syntaxhighlight>
{{out}}
<pre>
8
14
38
...
5648
5654
5738
</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">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))
</langsyntaxhighlight>{{out}}
<pre>
N Prime Triplet
Line 895 ⟶ 1,558:
5738 [5737, 5741, 5743]
</pre>
 
=={{header|Ksh}}==
<syntaxhighlight lang="ksh">
#!/bin/ksh
 
# numbers n such that n-1, n+3, and n+5 are all prime where: n < 6,000.
 
# # Variables:
#
integer MAX_n=6000
 
# # Functions:
#
 
# # Function _triplet(n, arr) build array of n-1, n+3, n+5
#
function _triplet {
typeset _n ; integer _n=$1
typeset _arr ; nameref _arr="$2"
 
_arr=( $((_n-1)) $((_n+3)) $((_n+5)) )
}
 
# # Function _isprime(n) return 1 for prime, 0 for not prime
#
function _isprime {
typeset _n ; integer _n=$1
typeset _i ; integer _i
 
(( _n < 2 )) && return 0
for (( _i=2 ; _i*_i<=_n ; _i++ )); do
(( ! ( _n % _i ) )) && return 0
done
return 1
}
 
######
# main #
######
 
for ((i=2; i<MAX_n; i++)); do
typeset -a arr
_triplet ${i} arr
for ((j=0; j<${#arr[*]}; j++)); do
_isprime ${arr[j]}
(( ! $? )) && unset arr && continue 2
done
oldIFS=${IFS}
IFS=\,
print "${i}: ${arr[*]}"
IFS=${oldIFS}
unset arr
done</syntaxhighlight>
{{out}}<pre>
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</pre>
 
=={{header|MAD}}==
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
BOOLEAN PRIME
DIMENSION PRIME(6005)
Line 921 ⟶ 1,684:
 
VECTOR VALUES FMT = $I4,3H =,3(I5)*$
END OF PROGRAM </langsyntaxhighlight>
{{out}}
<pre style='height:50ex'> 8 = 7 11 13
Line 969 ⟶ 1,732:
5654 = 5653 5657 5659
5738 = 5737 5741 5743</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">Select[Range[5999], PrimeQ[# - 1] && PrimeQ[# + 3] && PrimeQ[# + 5] &]</syntaxhighlight>
{{out}}
<pre>{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}</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
/* Function that find the number and the triple with the property */
triplets(n):=block(
L:makelist([i-1,i+3,i+5],i,1,n),
caching:length(L),
L1:[],
for i from 1 thru caching do if map(primep,L[i])=[true,true,true] then L1:endcons(append([[i]],L[i]),L1),
L1)$
 
/* Test case */
triplets(6000);
</syntaxhighlight>
{{out}}
<pre>
[[[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]]
</pre>
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strformat
 
const
Line 997 ⟶ 1,783:
inc count
 
echo &"\nFound {count} triplets for n < {N+1}."</langsyntaxhighlight>
 
{{out}}
Line 1,051 ⟶ 1,837:
 
=={{header|Perl}}==
{{libheader|ntheory}}
<lang perl>#!/usr/bin/perl
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
use strict; # https://rosettacode.org/wiki/Triplet_of_three_numbers
use warnings;
use ntheory qw( is_prime twin_primes );
 
is_prime($_ - 4) and printf "%5d" x 4 . "\n", $_ - 3, $_ - 4, $_, $_ + 2
my %cache;
for @{ twin_primes( 6000 ) };</syntaxhighlight>
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;
}</lang>
{{out}}
<pre>
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
</pre>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">trio</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">({</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">5</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">))=</span><span style="color: #000000;">3</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">trio</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d found: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<small>(assumes you can add {-1,3,5} to each number in your head easily enough)</small>
Line 1,127 ⟶ 1,909:
 
=={{header|PL/M}}==
<langsyntaxhighlight lang="plm">100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
Line 1,187 ⟶ 1,969:
END;
CALL EXIT;
EOF</langsyntaxhighlight>
{{out}}
<pre style='height:50ex'>8: 7, 11, 13
Line 1,236 ⟶ 2,018:
5738: 5737, 5741, 5743</pre>
 
=={{header|Quackery}}==
 
=={{header|Python}}==
<lang Quackery> [ 1 swap times [ i 1+ * ] ] is ! ( n --> n )
{{trans|FreeBASIC}}
<syntaxhighlight lang="python">
#!/usr/bin/python3
 
N = 6000
p = [None] * 6000 #inicializamos la lista
 
for i in range(2, round(pow(N,0.5))):
if not p[i]:
for j in range(i*2, N, i):
p[j] = 1
 
 
for i in range(3, N):
if (p[i-1] or p[i+3] or p[i+5]):
continue
else:
print(i, ': ', i-1, ' ', i+3, ' ', i+5)
</syntaxhighlight>
<pre>
Similar a la entrada de FreeBASIC.
</pre>
 
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery"> [ 1 swap times [ i 1+ * ] ] is ! ( n --> n )
 
[ dup 2 < iff
Line 1,253 ⟶ 2,060:
else drop ]
else drop ]
echo</langsyntaxhighlight>
 
{{out}}
Line 1,263 ⟶ 2,070:
A weird combination of [[Cousin primes]] and [[Twin primes]] that are siblings, but known by their neighbor.... I shall dub these Alabama primes.
 
<syntaxhighlight lang="raku" perl6line>say "{.[0]+1}: ",$_ for grep *.all.is-prime, ^6000 .race.map: { $_-1, $_+3, $_+5 };</langsyntaxhighlight>
{{out}}
<pre>8: (7 11 13)
Line 1,313 ⟶ 2,120:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX pgm finds prime triplets: n-1, n+3, n+5 are primes, and n < some specified #.*/
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 6000 /*Not specified? Then use the default.*/
Line 1,319 ⟶ 2,126:
call genP hi + 5 /*build semaphore array for low primes.*/
w= 30 /*width of a prime triplet in a column.*/
__= ' '; title= ' prime triplets: n-1, n+3, n+5 are primes, and n < ' commas(hi)
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
found= 0; idx= 1 idx= 1 /*initialize # prime triplets & index.*/
$=; __= ' ' /*a list of prime triplets (so far). */
do j=1 for hi-1 /*look for prime triplets within range.*/
p1= j - 1; if \!.p1 then iterate /*Is P1 not prime? Then skip it. */ /* ◄■■■■■■■ a filter.*/
p3= j + 3; if \!.p3 then iterate /* " P3 " " " " " */ /* ◄■■■■■■■ a filter.*/
p5= j + 5; if \!.p5 then iterate /* " P5 " " " " " */ /* ◄■■■■■■■ a filter.*/
found= found + 1 /*bump the number of prime triplets. */
if cols<=0 then iterate /*Build the list (to be shown later)? */
ttt= commas(p1)__ commas(p3)__ commas(p5) /*add commas & blanks to prime triplet.*/
$= $ left( '('ttt")", w) /*add a prime triplet ──► the $ list.*/
if found//cols\==0 then iterate /*have we populated a line of output? */
say center(idx, 7)'│' strip(substr($, 2), '"T'"); $= /*show what we have so far.*/
idx= idx + cols /*bump the index count for the output*/
end /*j*/
 
if $\=='' then say center(idx, 7)"│" strip(substr($, 2), 'T') /*possible show residual*/
if cols>0 then say '───────┴'center("" , , 1 + cols*(w+1), '─')
say
say 'Found ' commas(found) title
Line 1,348 ⟶ 2,155:
@.1=2; @.2=3; @.3=5; @.4=7; @.5=11 /*define some low primes. */
!.2=1; !.3=1; !.5=1; !.7=1; !.11=1 /* " " " " flags. */
#=5; ssq.#= @.# ** 2 /*number of primes so far; prime². */
/* [↓] generate more primes ≤ high.*/
do j=@.#+2 by 2 tofor max(0, hip %2-@.#%2-1) /*find odd primes from here on. */
parse var j '' -1 _; if if _==5 then iterate /*J divisible÷ by 5? (right digdigit).*/
if j//3==0 then iterate; if j// 37==0 then iterate /*" " " 3? Is J ÷ by 7? */
do k=5 while sq.k<=j if j// 7==0 then iterate /*" " " 7? [↓] divide by the known odd primes.*/
doif k=5 while sj//@.k<=j=0 then iterate j /*Is J÷@.k ? /*Then [↓]not prime. 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; ssq.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 1,381 ⟶ 2,187:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
see "working..." + nl
Line 1,403 ⟶ 2,209:
see "Found " + row + " prime triplets" + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,457 ⟶ 2,263:
Found 46 prime triplets
done...
</pre>
=={{header|RPL}}==
<code>PRIM?</code> is defined at [[Primality by trial division#RPL|Primality by trial division]]:
≪ { } 1 5
7 6000 '''FOR''' j
'''IF''' j <span style="color:blue>PRIM?</span> '''THEN'''
j SWAP -
'''IF''' DUP 2 == ROT 4 == AND '''THEN'''
SWAP j 5 - + SWAP '''END'''
j '''END'''
2 '''STEP''' DROP2
≫ '<span style="color:blue>TASK</span>' STO
{{out}}
<pre>
1: { 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 }
</pre>
Runs in 8 minutes 22 seconds on a basic HP-48G
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'prime'
 
primes = Prime.each(6000)
p primes.each_cons(3).filter_map{|p1, p2, p3| p1 + 1 if p1+4 == p2 && p1+6 == p3}
</syntaxhighlight>
{{out}}
<pre>[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]
</pre>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func boolean: isPrime (in integer: number) is func
Line 1,494 ⟶ 2,326:
end for;
writeln("\nFound " <& count <& " triplets for n < 6000.");
end func;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,550 ⟶ 2,382:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">^6000 -> grep {|n| [-1, 3, 5].all {|k| n + k -> is_prime } }.say</langsyntaxhighlight>
{{out}}
<pre>
[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]
</pre>
 
 
=={{header|True BASIC}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic">
LET n = 6000
 
DIM p(0)
MAT REDIM p(n)
 
FOR i = 2 TO SQR(n)
IF (NOT p(i) <> 0) THEN
FOR j = i*2 TO n STEP i
LET p(j) = 1
NEXT j
END IF
NEXT i
 
FOR i = 3 TO n
IF (p(i-1) <> 0 OR p(i+3) <> 0 OR p(i+5) <> 0) THEN
! en TB no exite un comando CONTINUE
ELSE
PRINT USING "####: #### #### ####": i, i-1, i+3, i+5
END IF
NEXT i
END
</syntaxhighlight>
{{out}}
<pre>
Similar a la entrada de FreeBASIC.
</pre>
 
=={{header|V (Vlang)}}==
{{trans|Python}}
<syntaxhighlight lang="v (vlang)">import math
 
const n = 6000
 
fn main() {
mut p := []bool{len:n, init:false}
for i in 2..int(math.round(math.pow(n,.5))) {
if !p[i] {
for j:=i*2;j<n;j+=i {
p[j] = true
}
}
}
for i in 3..n {
if p[i-1] || p[i+3] || p[i+5] {
continue
}
else {
println('$i : ${i-1} ${i+3} ${i+5}')
}
}
}</syntaxhighlight>
<pre>
Similar to Go
</pre>
 
Line 1,559 ⟶ 2,450:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
import "./fmt" for Fmt
 
var c = Int.primeSieve(6003, false)
Line 1,571 ⟶ 2,462:
}
for (n in numbers) Fmt.print("$,6d => $,6d", n, [n-1, n+3, n+5])
System.print("\nFound %(numbers.count) such numbers.")</langsyntaxhighlight>
 
{{out}}
Line 1,625 ⟶ 2,516:
Found 46 such numbers.
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
 
int Count, N;
[ChOut(0, ^ );
Count:= 0;
for N:= 3 to 6000-1 do
if IsPrime(N-1) & IsPrime(N+3) & IsPrime(N+5) then
[IntOut(0, N-1); ChOut(0, ^ );
IntOut(0, N+3); ChOut(0, ^ );
IntOut(0, N+5); ChOut(0, ^ );
Count:= Count+1;
if rem(Count/5) then ChOut(0, 9\tab\) else CrLf(0);
];
CrLf(0);
IntOut(0, Count);
Text(0, " prime triplets found below 6000.
");
]</syntaxhighlight>
 
{{out}}
<pre>
7 11 13 13 17 19 37 41 43 67 71 73 97 101 103
103 107 109 193 197 199 223 227 229 277 281 283 307 311 313
457 461 463 613 617 619 823 827 829 853 857 859 877 881 883
1087 1091 1093 1297 1301 1303 1423 1427 1429 1447 1451 1453 1483 1487 1489
1663 1667 1669 1693 1697 1699 1783 1787 1789 1867 1871 1873 1873 1877 1879
1993 1997 1999 2083 2087 2089 2137 2141 2143 2377 2381 2383 2683 2687 2689
2707 2711 2713 2797 2801 2803 3163 3167 3169 3253 3257 3259 3457 3461 3463
3463 3467 3469 3847 3851 3853 4153 4157 4159 4513 4517 4519 4783 4787 4789
5227 5231 5233 5413 5417 5419 5437 5441 5443 5647 5651 5653 5653 5657 5659
5737 5741 5743
46 prime triplets found below 6000.
</pre>
 
=={{header|Yabasic}}==
{{trans|Python}}
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Triplet_of_three_numbers
// by Galileo, 04/2022
 
N = 6000
dim p(N)
 
for i = 2 to int(N ^ 0.5)
if not p(i) then
for j = i*2 to N step i
p(j) = 1
next
endif
next
 
for i = 3 to N
if not (p(i-1) or p(i+3) or p(i+5)) print i, ": ", i-1, " ", i+3, " ", i+5
next</syntaxhighlight>
{{out}}
<pre>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
---Program done, press RETURN---</pre>
1,972

edits