Double Twin Primes: Difference between revisions

Added Sidef
(Added XPL0 example.)
(Added Sidef)
 
(37 intermediate revisions by 15 users not shown)
Line 1:
{{draft task}}
'''Definition'''
<br>
Line 12 ⟶ 13:
<br>
Find and show here all Double Twin Primes under 1000.
<br><br>
;See also
:* [[oeis:A007530|OEIS:A007530]]
:* [[wp:Prime_k-tuple|Wikipedia:Prime_k-tuple]]
<br><br>
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<syntaxhighlight lang="algol68">
BEGIN # find some sequences of primes where the gaps between the elements #
# are 2, 4, 2 - i.e., n, n+2, n+6 and n+8 are all prime #
PR read "primes.incl.a68" PR # include prime utilities #
[]BOOL prime = PRIMESIEVE 1 000;
INT count := 0;
INT p := 3; # 2 cannot be a twin prime, so start with 3 #
WHILE p <= UPB prime - 8 DO
BOOL is double twin := FALSE;
IF prime[ p ] THEN
IF prime[ p + 2 ] THEN
IF prime[ p + 6 ] THEN
IF prime[ p + 8 ] THEN
count +:= 1;
is double twin := TRUE;
print( ( "["
, whole( p, -4 ), whole( p + 2, -4 )
, whole( p + 6, -4 ), whole( p + 8, -4 )
, " ]"
, newline
)
)
FI
FI
FI
FI;
p +:= IF is double twin THEN 6 ELSE 2 FI
OD;
print( ( "Found ", whole( count, 0 ), " double twin primes below ", whole( UPB prime, 0 ), newline ) )
END
</syntaxhighlight>
{{out}}
<pre>
[ 5 7 11 13 ]
[ 11 13 17 19 ]
[ 101 103 107 109 ]
[ 191 193 197 199 ]
[ 821 823 827 829 ]
Found 5 double twin primes beflow 1000
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">r: range .step: 2 1 1000
r | map 'x -> @[x x+2 x+6 x+8]
| select => [every? & => prime?]
| loop => print</syntaxhighlight>
 
{{out}}
 
<pre>5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">#include "isPrime.kbs"
 
num = 3
while num < 992
if isPrime(num) then
if isPrime(num+2) then
if isPrime(num+6) then
if isPrime(num+8) then print num; " "; num+2; " "; num+6; " "; num+8
end if
end if
end if
num += 2
end while
end</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
 
Dim num As Integer = 3
Do
If isPrime(num) Then
If isPrime(num + 2) Then
If isPrime(num + 6) Then
If isPrime(num + 8) Then Print num; " "; num + 2; " "; num + 6; " "; num + 8
End If
End If
End If
num += 2
Loop Until num > 992
 
End
 
Public Sub isPrime(ValorEval As Long) As Boolean
If ValorEval < 2 Then Return False
If ValorEval Mod 2 = 0 Then Return ValorEval = 2
If ValorEval Mod 3 = 0 Then Return ValorEval = 3
Dim d As Long = 5
While d * d <= ValorEval
If ValorEval Mod d = 0 Then Return False Else d += 2
Wend
Return True
End Function </syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="purebasic">Procedure.b isPrime(v.i)
If v <= 1 : ProcedureReturn #False
ElseIf v < 4 : ProcedureReturn #True
ElseIf v % 2 = 0 : ProcedureReturn #False
ElseIf v < 9 : ProcedureReturn #True
ElseIf v % 3 = 0 : ProcedureReturn #False
Else
Protected r = Round(Sqr(v), #PB_Round_Down)
Protected f = 5
While f <= r
If v % f = 0 Or v % (f + 2) = 0
ProcedureReturn #False
EndIf
f + 6
Wend
EndIf
ProcedureReturn #True
EndProcedure
 
OpenConsole()
num.I = 3
While num < 992
If isPrime(num):
If isPrime(num+2):
If isPrime(num+6):
If isPrime(num+8):
PrintN(Str(num) + " " + Str(num+2) + " " + Str(num+6) + " " + Str(num+8))
EndIf
EndIf
EndIf
EndIf
num + 2
Wend
 
Input()
CloseConsole();</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Run BASIC}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">function isPrime(n)
if n < 2 then isPrime = 0 : goto [exit]
if n = 2 then isPrime = 1 : goto [exit]
if n mod 2 = 0 then isPrime = 0 : goto [exit]
isPrime = 1
for i = 3 to int(n^.5) step 2
if n mod i = 0 then isPrime = 0 : goto [exit]
next i
[exit]
end function
 
num = 3
while num < 992
if isPrime(num) then
if isPrime(num+2) then
if isPrime(num+6) then
if isPrime(num+8) then print num; " "; num+2; " "; num+6; " "; num+8
end if
end if
end if
num = num + 2
wend
end</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{Header|Tiny BASIC}}===
<syntaxhighlight lang="qbasic">REM Rosetta Code problem: https://rosettacode.org/wiki/Double_Twin_Primes
REM by Jjuanhdez, 03/2023
 
LET I = 3
10 LET X = I
GOSUB 100
IF Z = 1 THEN LET X = I + 2
IF Z = 1 THEN GOSUB 100
IF Z = 1 THEN LET X = I + 6
IF Z = 1 THEN GOSUB 100
IF Z = 1 THEN LET X = I + 8
IF Z = 1 THEN GOSUB 100
IF Z = 1 THEN PRINT I, " ", I + 2, " ", I + 6, " ", I + 8
LET I = I + 2
IF I > 992 THEN GOTO 20
GOTO 10
20 END
 
100 REM is X a prime? Z=1 for yes, 0 for no
LET Z = 1
IF X = 3 THEN RETURN
IF X = 2 THEN RETURN
LET A = 1
110 LET A = A + 1
IF (X / A) * A = X THEN GOTO 120
IF A * A <= X THEN GOTO 110
RETURN
120 LET Z = 0
RETURN</syntaxhighlight>
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|XBasic}}===
{{trans|BASIC256}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "DoubleTwinPrimes"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
INTERNAL FUNCTION ISPrime(n%%)
 
FUNCTION Entry ()
num%% = 3
DO
IF ISPrime(num%%) THEN
IF ISPrime(num%%+2) THEN
IF ISPrime(num%%+6) THEN
IF ISPrime(num%%+8) THEN
PRINT num%%; num%%+2; num%%+6; num%%+8
ENDIF
ENDIF
ENDIF
ENDIF
num%% = num%% + 2
LOOP UNTIL num%% > 992
END FUNCTION
 
FUNCTION ISPrime(n%%)
IF n%% < 2 THEN RETURN $$FALSE
IF n%% MOD 2 = 0 THEN RETURN n%% = 2
IF n%% MOD 3 = 0 THEN RETURN n%% = 3
d%% = 5
DO WHILE d%% * d%% <= n%%
IF n%% MOD d%% = 0 THEN RETURN $$FALSE ELSE d%% = d%% + 2
LOOP
RETURN $$TRUE
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
<pre>Same as BASIC256 entry.</pre>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">//import isPrime
 
num = 3
repeat
if isPrime(num) if isPrime(num+2) if isPrime(num+6) if isPrime(num+8) print num, " ", num+2, " ", num+6, " ", num+8
num = num + 2
until num > 992
end</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|C}}==
<syntaxhighlight lang ="c">#include <stdio.h>
#include <stdbool.h>
 
bool isPrime(int n) {
if (n < 2) return false;
if (n%2 == 0) return n == 2;
if (n%3 == 0) return n == 3;
int d = 5;
while (d*d <= n) {
if (n%d == 0) return false;
d += 2;
if (n%d == 0) return false;
d += 4;
}
return true;
}
 
int main() {
printf("Double twin primes under 1,000:\n");
for (int i = 3; i < 992; i+=2) {
if (isPrime(i) && isPrime(i+2) && isPrime(i+6) && isPrime(i+8)) {
printf("%4d %4d %4d %4d\n", i, i+2, i+6, i+8);
}
}
return 0;
}</syntaxhighlight>
 
{{out}}
<pre>
Double twin primes under 1,000:
5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829
</pre>
 
=={{header|Dart}}==
<syntaxhighlight lang="dart">import 'dart:math';
 
void main() {
for (int num = 3; num < 992; num += 2) {
if (isPrime(num) &&
isPrime(num + 2) &&
isPrime(num + 6) &&
isPrime(num + 8)) {
print("$num ${num + 2} ${num + 6} ${num + 8}");
}
}
}
 
bool isPrime(int n) {
if (n <= 1) return false;
if (n == 2) return true;
for (int i = 2; i <= sqrt(n); ++i) {
if (n % i == 0) return false;
}
return true;
}</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|Classes,SysUtils,StdCtrls}}
Uses standard TList as FIFO to hold and test groups of four sequentail prime numbers.
 
<syntaxhighlight lang="Delphi">
 
 
function IsPrime(N: integer): boolean;
{Fast, optimised prime test}
var I,Stop: integer;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (I + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
 
function GetNextPrime(var Start: integer): integer;
{Get the next prime number after Start}
{Start is passed by "reference," so the
{original variable is incremented}
begin
repeat Inc(Start)
until IsPrime(Start);
Result:=Start;
end;
 
procedure ShowDoubleTwinPrimes(Memo: TMemo);
{Find sets of four primes P1,P2,P3,P4, where}
{P2-P1=2 P4-P3=2 and P3-P2=4 }
{Use TList as FIFO to test all four-prime combinations}
var LS: TList;
var Start: integer;
begin
LS:=TList.Create;
try
Start:=0;
while true do
begin
{Put four primes in the list}
repeat LS.Add(Pointer(GetNextPrime(Start)))
until LS.Count=4;
if Integer(LS[3])>=1000 then break;
{Test if they are double twin prime}
if (Integer(LS[1])-Integer(LS[0])=2) and
(Integer(LS[3])-Integer(LS[2])=2) and
(Integer(LS[2])-Integer(LS[1])=4) then
begin
{Display the result}
Memo.Lines.Add(IntToStr(Integer(LS[0]))+' '+
IntToStr(Integer(LS[1]))+' '+
IntToStr(Integer(LS[2]))+' '+
IntToStr(Integer(LS[3])));
end;
{Delete the first prime}
LS.Delete(0);
end;
finally LS.Free; end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829
</pre>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vb">#include "isprime.bas"
 
Dim As Uinteger num = 3
Do
If isPrime(num) Then
If isPrime(num+2) Then
If isPrime(num+6) Then
If isPrime(num+8) Then Print num; " "; num+2; " "; num+6; " "; num+8
End If
End If
End If
num += 2
Loop Until num > 992
 
Sleep</syntaxhighlight>
{{out}}
<pre>5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn IsPrime( n as long ) as BOOL
long i
BOOL result = YES
if ( n < 2 ) then result = NO : exit fn
for i = 2 to n + 1
if ( i * i <= n ) and ( n mod i == 0 )
result = NO : exit fn
end if
next
end fn = result
 
local fn DoubleTwinPrimes( limit as long )
NSUInteger num = 3
printf @"Double twin primes < %ld:", limit
do
if fn IsPrime( num )
if fn IsPrime( num + 2 )
if fn IsPrime( num + 6 )
if fn IsPrime( num + 8 ) then printf @"%4lu%7lu%7lu%7lu", num, num + 2, num + 6, num + 8
end if
end if
end if
num += 2
until ( num > limit )
end fn
 
fn DoubleTwinPrimes( 2000 )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Double twin primes < 2000:
5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829
1481 1483 1487 1489
1871 1873 1877 1879
</pre>
 
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<syntaxhighlight lang="go">package main
 
import (
"fmt"
"rcu"
)
 
func main() {
p := rcu.Primes(1000)
fmt.Println("Double twin primes under 1,000:")
for i := 1; i < len(p)-3; i++ {
if p[i+1]-p[i] == 2 && p[i+2]-p[i+1] == 4 && p[i+3]-p[i+2] == 2 {
fmt.Printf("%4d\n", p[i:i+4])
}
}
}</syntaxhighlight>
 
{{out}}
<pre>
Double twin primes under 1,000:
[ 5 7 11 13]
[ 11 13 17 19]
[ 101 103 107 109]
[ 191 193 197 199]
[ 821 823 827 829]
</pre>
 
=={{header|J}}==
<syntaxhighlight lang=J> _6 _4 0 2+/~(#~ 0,4=2-~/\])p:~.,0 1+/~/I.2=2 -~/\ i.&.(p:inv) 1000
5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829</syntaxhighlight>
 
Breaking this down:
 
<syntaxhighlight lang=J> primes=: i.&.(p:inv) 1000
twinprimes=: p:~.,0 1+/~/I.2=2 -~/\ primes
doubletwinprimes=: _6 _4 0 2+/~(#~ 0,4=2-~/\])</syntaxhighlight>
 
The first two expressions rely on the primitive <code>p:</code> which translates between the index of a prime number and the prime itself. The final expression instead filters the remaining primes (because the sequence of primes which was its argument had already been filtered enough to have made indices into that sequence into relevant information which was not worth recalculating).
 
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">
# Input: a positive integer
# Output: an array, $a, of length .+1 such that
# $a[$i] is $i if $i is prime, and false otherwise.
def primeSieve:
# erase(i) sets .[i*j] to false for integral j > 1
def erase(i):
if .[i] then
reduce (range(2*i; length; i)) as $j (.; .[$j] = false)
else .
end;
(. + 1) as $n
| (($n|sqrt) / 2) as $s
| [null, null, range(2; $n)]
| reduce (2, 1 + (2 * range(1; $s))) as $i (.; erase($i)) ;
 
def double_twin_primes($n):
[$n|primeSieve|range(0;length) as $i | select(.[$i]) | $i] as $p
| range(1; $p|length-3) as $i
| select( ($p[$i+1] - $p[$i]) == 2 and ($p[$i+2] - $p[$i+1]) == 4 and ($p[$i+3] - $p[$i+2]) == 2 )
| [$p[$i, $i+1, $i+2, $i+3]] ;
 
 
"Double twin primes under 1,000:",
double_twin_primes(1000)
</syntaxhighlight>
{{output}}
<pre>
Double twin primes under 1,000:
[5,7,11,13]
[11,13,17,19]
[101,103,107,109]
[191,193,197,199]
[821,823,827,829]
</pre>
 
=={{header|Julia}}==
{{trans|C}}
<syntaxhighlight lang="julia">using Primes
using Printf
 
function printdt(N)
@printf("Double twin primes under 1,000:\n")
for i in 3:2:N-8
if isprime(i) && isprime(i+2) && isprime(i+6) && isprime(i+8)
@printf("%4d %4d %4d %4d\n", i, i+2, i+6, i+8)
end
end
end
 
printdt(1000)
</syntaxhighlight>{{out}} Same as C example.
 
=={{header|Nim}}==
<syntaxhighlight lang="Nim">import std/strformat
 
func isPrime(n: Positive): bool =
if n < 2: return false
if (n and 1) == 0: return n == 2
if n mod 3 == 0: return n == 3
var k = 5
var delta = 2
while k * k <= n:
if n mod k == 0: return false
inc k, delta
delta = 6 - delta
result = true
 
echo "Double twin primes under 1000:"
for n in countup(3, 991, 2):
if isPrime(n) and isPrime(n + 2) and isPrime(n + 6) and isPrime(n + 8):
echo &"({n:>3}, {n+2:>3}, {n+6:>3}, {n+8:>3})"
</syntaxhighlight>
 
{{out}}
<pre>( 5, 7, 11, 13)
( 11, 13, 17, 19)
(101, 103, 107, 109)
(191, 193, 197, 199)
(821, 823, 827, 829)
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36;
use ntheory 'is_prime';
 
sub dt ($p) { map { $p + $_ } <0 2 6 8> }
for my $n (1..1000) { say "@{[dt $n]}" if 4 == +(grep { is_prime $_ } dt $n) }</syntaxhighlight>
{{out}}
<pre>5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">p</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">3</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">3</span><span style="color: #0000FF;">]-</span><span style="color: #000000;">p</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">8</span> <span style="color: #008080;">and</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]-</span><span style="color: #000000;">p</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">4</span> <span style="color: #008080;">then</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;">"%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">..</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">3</span><span style="color: #0000FF;">],</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">:=</span><span style="color: #008000;">"%4d"</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829
</pre>
 
=={{header|Python}}==
<syntaxhighlight lang="python">#!/usr/bin/python
 
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
if __name__ == "__main__":
num = 3
while num <= 1000:
if isPrime(num):
if isPrime(num+2):
if isPrime(num+6):
if isPrime(num+8):
print(num, num+2, num+6, num+8, sep="\t")
num += 2</syntaxhighlight>
{{out}}
<pre>5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829</pre>
 
=={{header|Raku}}==
Cousin twin primes:
Line 26 ⟶ 700:
=={{header|Ring}}==
<syntaxhighlight lang="ring">
see "worksworking..." + nl
primesP = []
 
limit = 1000
for n =1 to limit
if isPrimeisP(n)
add(primesP,n)
ok
next
lenPrimeslenP = len(primesP)-3
for m = 1 to lenPrimeslenP
if isPrimeisP(primesP[m]) andAND isPrimeisP(primesP[m+1]) andAND isP(P[m+2]) AND isP(P[m+3])
isPrimeif (primesP[m+1] - P[m] = 2) AND (P[m+2] - P[m+1] = 4) andAND isPrime(primesP[m+3] - P[m+2] = 2)
if (primes see " " + P[m+1]+ -" " + primesP[m+1] =+ 2)" and" (primes+ P[m+2] -+ " " + primesP[m+13] = 4) and+ nl
(primes[m+3] - primes[m+2] = 2)
see " " + primes[m]+ " " + primes[m+1] + " " +
primes[m+2] + " " + primes[m+3] + nl
ok
ok
next
 
see "done..." + nl
 
func isPrimeisP num
if (num <= 1) return 0 ok
if (num % 2 = 0 andAND num != 2) return 0 ok
for i = 3 to floor(num / 2) -1 step 2
if (num % i = 0) return 0 ok
next
return 1
</syntaxhighlight>
{{out}}
Line 64 ⟶ 737:
821 823 827 829
done...
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'prime'
 
res = Prime.each(1000).each_cons(4).select do |p1, p2, p3, p4|
p1+2 == p2 && p2+4 == p3 && p3+2 == p4
end
 
res.each{|slice| puts slice.join(", ")}
</syntaxhighlight>
{{out}}
<pre>5, 7, 11, 13
11, 13, 17, 19
101, 103, 107, 109
191, 193, 197, 199
821, 823, 827, 829
</pre>
 
=={{header|Sidef}}==
 
<syntaxhighlight lang="ruby">1000.primes.each_cons(4, {|*a|
if (a.diffs == [2, 4, 2]) {
say a
}
})</syntaxhighlight>
{{out}}
<pre>
[5, 7, 11, 13]
[11, 13, 17, 19]
[101, 103, 107, 109]
[191, 193, 197, 199]
[821, 823, 827, 829]
</pre>
 
=={{header|V (Vlang)}}==
{{trans|Ring}}
<syntaxhighlight lang="Zig">
import math
 
fn main() {
limit := 1000
mut parr := []int{}
for n in 1..limit {
if is_prime(n) {parr << n}
}
for m in 1..parr.len - 3 {
if is_prime(parr[m]) && is_prime(parr[m + 1]) && is_prime(parr[m + 2]) && is_prime(parr[m + 3]) {
if parr[m + 1] - parr[m] == 2 && parr[m + 2] - parr[m + 1] == 4 && parr[m + 3] - parr[m + 2] == 2 {
println("${parr[m]} ${parr[m + 1]} ${parr[m + 2]} ${parr[m + 3]}")
}
}
}
}
 
fn is_prime(num i64) bool {
if num <= 1 {return false}
if num % 2 == 0 && num != 2 {return false}
for idx := 3; idx <= math.floor(num / 2) - 1; idx += 2 {
if num % idx == 0 {return false}
}
return true
}
</syntaxhighlight>
 
{{out}}
<pre>
5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="wren">import "./math" for Int
import "./fmt" for Fmt
 
var p = Int.primeSieve(1000)
System.print("Double twin primes under 1,000:")
for (i in 1...p.count-3) {
if (p[i+1] - p[i] == 2 && p[i+2] - p[i+1] == 4 && p[i+3] - p[i+2] == 2) {
Fmt.aprint(p[i..i+3], 4, 0, "")
}
}</syntaxhighlight>
 
{{out}}
<pre>
Double twin primes under 1,000:
5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829
</pre>
 
2,747

edits