Prime triplets: Difference between revisions

Content added Content deleted
(Added Sidef)
m (syntax highlighting fixup automation)
Line 16: Line 16:
{{trans|Nim}}
{{trans|Nim}}


<lang 11l>F is_prime(n)
<syntaxhighlight lang="11l">F is_prime(n)
I n == 2
I n == 2
R 1B
R 1B
Line 33: Line 33:
count++
count++


print("\nFound "count‘ primes triplets for p < 5500.’)</lang>
print("\nFound "count‘ primes triplets for p < 5500.’)</syntaxhighlight>


{{out}}
{{out}}
Line 87: Line 87:
=={{header|Action!}}==
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
{{libheader|Action! Sieve of Eratosthenes}}
<lang Action!>INCLUDE "H6:SIEVE.ACT"
<syntaxhighlight lang="action!">INCLUDE "H6:SIEVE.ACT"


PROC Main()
PROC Main()
Line 104: Line 104:
OD
OD
PrintF("%E%EThere are %I prime triplets",count)
PrintF("%E%EThere are %I prime triplets",count)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Prime_triplets.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Prime_triplets.png Screenshot from Atari 8-bit computer]
Line 120: Line 120:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Using code from [[Successive_prime_differences#ALGOL_68]]
Using code from [[Successive_prime_differences#ALGOL_68]]
<lang algol68>BEGIN # find primes p where p+2 and p+6 are also prime #
<syntaxhighlight lang="algol68">BEGIN # find primes p where p+2 and p+6 are also prime #
# reurns a list of primes up to n #
# reurns a list of primes up to n #
PROC prime list = ( INT n )[]INT:
PROC prime list = ( INT n )[]INT:
Line 175: Line 175:
print( ( "Prime triplets under ", whole( max number, 0 ), ":", newline ) );
print( ( "Prime triplets under ", whole( max number, 0 ), ":", newline ) );
try differences( p list, ( 2, 4 ) )
try differences( p list, ( 2, 4 ) )
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 192: Line 192:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>lst: select select 2..5500 => prime? 'x
<syntaxhighlight lang="rebol">lst: select select 2..5500 => prime? 'x
-> and? [prime? x+2] [prime? x+6]
-> and? [prime? x+2] [prime? x+6]


Line 199: Line 199:
pad join.with:", "
pad join.with:", "
to [:string] @[item item+2 item+6] 17
to [:string] @[item item+2 item+6] 17
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 214: Line 214:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f PRIME_TRIPLETS.AWK
# syntax: GAWK -f PRIME_TRIPLETS.AWK
BEGIN {
BEGIN {
Line 239: Line 239:
return(1)
return(1)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 291: Line 291:
=={{header|BASIC}}==
=={{header|BASIC}}==
==={{header|BASIC256}}===
==={{header|BASIC256}}===
<lang BASIC256>function isPrime(v)
<syntaxhighlight lang="basic256">function isPrime(v)
if v < 2 then return False
if v < 2 then return False
if v mod 2 = 0 then return v = 2
if v mod 2 = 0 then return v = 2
Line 308: Line 308:
print "["; p; " "; p+2; " "; p+6; "]"
print "["; p; " "; p+2; " "; p+6; "]"
next p
next p
end</lang>
end</syntaxhighlight>


==={{header|PureBasic}}===
==={{header|PureBasic}}===
<lang PureBasic>Procedure isPrime(v.i)
<syntaxhighlight lang="purebasic">Procedure isPrime(v.i)
If v <= 1 : ProcedureReturn #False
If v <= 1 : ProcedureReturn #False
ElseIf v < 4 : ProcedureReturn #True
ElseIf v < 4 : ProcedureReturn #True
Line 344: Line 344:
Next p
Next p
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
CloseConsole()</lang>
CloseConsole()</syntaxhighlight>


==={{header|Yabasic}}===
==={{header|Yabasic}}===
<lang yabasic>
<syntaxhighlight lang="yabasic">
sub isPrime(v)
sub isPrime(v)
if v < 2 then return False : fi
if v < 2 then return False : fi
Line 365: Line 365:
print "[", p using "####", p+2 using "####", p+6 using "####", "]"
print "[", p using "####", p+2 using "####", p+6 using "####", "]"
next p
next p
end</lang>
end</syntaxhighlight>




=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.98}}
{{works with|Factor|0.98}}
<lang factor>USING: arrays kernel lists lists.lazy math math.primes
<syntaxhighlight lang="factor">USING: arrays kernel lists lists.lazy math math.primes
math.primes.lists prettyprint sequences ;
math.primes.lists prettyprint sequences ;


Line 377: Line 377:
[ [ prime? ] all? ] lfilter ! Select triplets which contain only primes
[ [ prime? ] all? ] lfilter ! Select triplets which contain only primes
[ first 5500 < ] lwhile ! Make the list end eventually...
[ first 5500 < ] lwhile ! Make the list end eventually...
[ . ] leach ! Print each item in the list</lang>
[ . ] leach ! Print each item in the list</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:14em">
<pre style="height:14em">
Line 426: Line 426:


=={{header|Fermat}}==
=={{header|Fermat}}==
<lang fermat>for i=3,5499,2 do if Isprime(i)=1 and Isprime(i+2)=1 and Isprime(i+6)=1 then !!(i,i+2,i+6) fi od</lang>
<syntaxhighlight lang="fermat">for i=3,5499,2 do if Isprime(i)=1 and Isprime(i+2)=1 and Isprime(i+6)=1 then !!(i,i+2,i+6) fi od</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>#include "isprime.bas"
<syntaxhighlight lang="freebasic">#include "isprime.bas"
for p as uinteger = 3 to 5499 step 2
for p as uinteger = 3 to 5499 step 2
if not isprime(p+6) then continue for
if not isprime(p+6) then continue for
Line 435: Line 435:
if not isprime(p) then continue for
if not isprime(p) then continue for
print using "[#### #### ####] ";p;p+2;p+6;
print using "[#### #### ####] ";p;p+2;p+6;
next p</lang>
next p</syntaxhighlight>
{{out}}<pre>
{{out}}<pre>
[ 5 7 11] [ 11 13 17] [ 17 19 23] [ 41 43 47] [ 101 103 107] [ 107 109 113] [ 191 193 197] [ 227 229 233] [ 311 313 317] [ 347 349 353] [ 461 463 467] [ 641 643 647] [ 821 823 827] [ 857 859 863] [ 881 883 887] [1091 1093 1097] [1277 1279 1283] [1301 1303 1307] [1427 1429 1433] [1481 1483 1487] [1487 1489 1493] [1607 1609 1613] [1871 1873 1877] [1997 1999 2003] [2081 2083 2087] [2237 2239 2243] [2267 2269 2273] [2657 2659 2663] [2687 2689 2693] [3251 3253 3257] [3461 3463 3467] [3527 3529 3533] [3671 3673 3677] [3917 3919 3923] [4001 4003 4007] [4127 4129 4133] [4517 4519 4523] [4637 4639 4643] [4787 4789 4793] [4931 4933 4937] [4967 4969 4973] [5231 5233 5237] [5477 5479 5483]
[ 5 7 11] [ 11 13 17] [ 17 19 23] [ 41 43 47] [ 101 103 107] [ 107 109 113] [ 191 193 197] [ 227 229 233] [ 311 313 317] [ 347 349 353] [ 461 463 467] [ 641 643 647] [ 821 823 827] [ 857 859 863] [ 881 883 887] [1091 1093 1097] [1277 1279 1283] [1301 1303 1307] [1427 1429 1433] [1481 1483 1487] [1487 1489 1493] [1607 1609 1613] [1871 1873 1877] [1997 1999 2003] [2081 2083 2087] [2237 2239 2243] [2267 2269 2273] [2657 2659 2663] [2687 2689 2693] [3251 3253 3257] [3461 3463 3467] [3527 3529 3533] [3671 3673 3677] [3917 3919 3923] [4001 4003 4007] [4127 4129 4133] [4517 4519 4523] [4637 4639 4643] [4787 4789 4793] [4931 4933 4937] [4967 4969 4973] [5231 5233 5237] [5477 5479 5483]
Line 443: Line 443:
{{trans|Wren}}
{{trans|Wren}}
{{libheader|Go-rcu}}
{{libheader|Go-rcu}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 467: Line 467:
}
}
fmt.Println("\nFound", len(triples), "such prime triplets.")
fmt.Println("\nFound", len(triples), "such prime triplets.")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 475: Line 475:


=={{header|GW-BASIC}}==
=={{header|GW-BASIC}}==
<lang gwbasic>10 FOR A = 3 TO 5499 STEP 2
<syntaxhighlight lang="gwbasic">10 FOR A = 3 TO 5499 STEP 2
20 P = A
20 P = A
30 GOSUB 1000
30 GOSUB 1000
Line 491: Line 491:
1020 I = I + 1
1020 I = I + 1
1030 IF I*I > P THEN RETURN
1030 IF I*I > P THEN RETURN
1040 GOTO 1010</lang>
1040 GOTO 1010</syntaxhighlight>


=={{header|jq}}==
=={{header|jq}}==
Line 500: Line 500:


The `prime_triplets` defined here generates an unbounded stream of prime triples, which is harnessed by the generic function `emit_until` defined as follows:
The `prime_triplets` defined here generates an unbounded stream of prime triples, which is harnessed by the generic function `emit_until` defined as follows:
<syntaxhighlight lang="jq">
<lang jq>
def emit_until(cond; stream): label $out | stream | if cond then break $out else . end;</lang>
def emit_until(cond; stream): label $out | stream | if cond then break $out else . end;</syntaxhighlight>
The Task:
The Task:
<lang jq># Output: [p,p+2,p+6] where p is prime
<syntaxhighlight lang="jq"># Output: [p,p+2,p+6] where p is prime
def prime_triplets:
def prime_triplets:
def pt: .[2] == .[1] + 4 and .[1] == .[0] + 2;
def pt: .[2] == .[1] + 4 and .[1] == .[0] + 2;
Line 510: Line 510:
foreach range(7; infinite; 2) as $i ([2,3,5]; next; select(pt) ) ;
foreach range(7; infinite; 2) as $i ([2,3,5]; next; select(pt) ) ;


emit_until(.[0] >= 5500; prime_triplets) </lang>
emit_until(.[0] >= 5500; prime_triplets) </syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 559: Line 559:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Primes
<syntaxhighlight lang="julia">using Primes


pmask = primesmask(1, 5505)
pmask = primesmask(1, 5505)
foreach(n -> println([n, n + 2, n + 6]), filter(n -> pmask[n] && pmask[n + 2] && pmask[n + 6], 1:5500))
foreach(n -> println([n, n + 2, n + 6]), filter(n -> pmask[n] && pmask[n + 2] && pmask[n + 6], 1:5500))
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
[5, 7, 11]
[5, 7, 11]
Line 610: Line 610:
</pre>
</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>Cases[Partition[Most@NestWhileList[NextPrime, 2, # < 5500 &], 3,
<syntaxhighlight lang="mathematica">Cases[Partition[Most@NestWhileList[NextPrime, 2, # < 5500 &], 3,
1], _?(Differences[#] == {2, 4} &)] // TableForm</lang>
1], _?(Differences[#] == {2, 4} &)] // TableForm</syntaxhighlight>


{{out}}<pre>
{{out}}<pre>
Line 660: Line 660:


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>import strformat
<syntaxhighlight lang="nim">import strformat


const
const
Line 686: Line 686:
inc count
inc count


echo &"\nFound {count} primes triplets for p < {N+1}."</lang>
echo &"\nFound {count} primes triplets for p < {N+1}."</syntaxhighlight>


{{out}}
{{out}}
Line 737: Line 737:


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>for(i=1,5499,if(isprime(i)&&isprime(i+2)&&isprime(i+6),print(i," ",i+2," ",i+6)))</lang>
<syntaxhighlight lang="parigp">for(i=1,5499,if(isprime(i)&&isprime(i+2)&&isprime(i+6),print(i," ",i+2," ",i+6)))</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>#!/usr/bin/perl
<syntaxhighlight lang="perl">#!/usr/bin/perl


use strict;
use strict;
Line 748: Line 748:


is_prime($_ + 6) and printf "%5d" x 3 . "\n", $_, $_ + 2, $_ + 6
is_prime($_ + 6) and printf "%5d" x 3 . "\n", $_, $_ + 2, $_ + 6
for @{ twin_primes( 5500 ) };</lang>
for @{ twin_primes( 5500 ) };</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 797: Line 797:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">pt</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">+</span><span style="color: #000000;">6</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">pt</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">+</span><span style="color: #000000;">6</span><span style="color: #0000FF;">)</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;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">5500</span><span style="color: #0000FF;">),</span><span style="color: #000000;">pt</span><span style="color: #0000FF;">)</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;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">5500</span><span style="color: #0000FF;">),</span><span style="color: #000000;">pt</span><span style="color: #0000FF;">)</span>
Line 803: Line 803:
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"(%d %d %d)"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"(%d %d %d)"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">res</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;">"Found %d prime triplets: %s\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;">join</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;">2</span><span style="color: #0000FF;">),</span><span style="color: #008000;">", "</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;">"Found %d prime triplets: %s\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;">join</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;">2</span><span style="color: #0000FF;">),</span><span style="color: #008000;">", "</span><span style="color: #0000FF;">)})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 811: Line 811:


=={{header|Python}}==
=={{header|Python}}==
<lang python>#!/usr/bin/python
<syntaxhighlight lang="python">#!/usr/bin/python


def isPrime(n):
def isPrime(n):
Line 827: Line 827:
if not isPrime(p):
if not isPrime(p):
continue
continue
print(f'[{p} {p+2} {p+6}]')</lang>
print(f'[{p} {p+2} {p+6}]')</syntaxhighlight>




Line 834: Line 834:
===Filter===
===Filter===
Favoring brevity over efficiency due to the small range of n, the most concise solution is:
Favoring brevity over efficiency due to the small range of n, the most concise solution is:
<lang perl6>say grep *.all.is-prime, map { $_, $_+2, $_+6 }, 2..5500;</lang>
<syntaxhighlight lang="raku" line>say grep *.all.is-prime, map { $_, $_+2, $_+6 }, 2..5500;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 842: Line 842:
A more efficient and versatile approach is to generate an infinite list of triple primes, using this info from https://oeis.org/A022004 :
A more efficient and versatile approach is to generate an infinite list of triple primes, using this info from https://oeis.org/A022004 :
:All terms are congruent to 5 (mod 6).
:All terms are congruent to 5 (mod 6).
<lang perl6>constant @triples = (5, *+6 … *).map: -> \n { $_ if .all.is-prime given (n, n+2, n+6) }
<syntaxhighlight lang="raku" line>constant @triples = (5, *+6 … *).map: -> \n { $_ if .all.is-prime given (n, n+2, n+6) }


my $count = @triples.first: :k, *.[0] >= 5500;
my $count = @triples.first: :k, *.[0] >= 5500;


say .fmt('%4d') for @triples.head($count);</lang>
say .fmt('%4d') for @triples.head($count);</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 894: Line 894:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program finds prime triplets: P, P+2, P+6 are primes, and P < some specified N*/
<syntaxhighlight lang="rexx">/*REXX program finds prime triplets: P, P+2, P+6 are primes, and P < some specified N*/
parse arg hi cols . /*obtain optional argument from the CL.*/
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 5500 /*Not specified? Then use the default.*/
if hi=='' | hi=="," then hi= 5500 /*Not specified? Then use the default.*/
Line 941: Line 941:
end /*k*/ /* [↑] only process numbers ≤ √ J */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</lang>
end /*j*/; return</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
Line 963: Line 963:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
load "stdlib.ring"
load "stdlib.ring"
see "working..." + nl
see "working..." + nl
Line 980: Line 980:
see "Found " + row + " primes" + nl
see "Found " + row + " primes" + nl
see "done..." + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,035: Line 1,035:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>say "Values of p such that (p, p+2, p+6) are all prime:"
<syntaxhighlight lang="ruby">say "Values of p such that (p, p+2, p+6) are all prime:"
5500.primes.grep{|p| all_prime(p+2, p+6) }.say</lang>
5500.primes.grep{|p| all_prime(p+2, p+6) }.say</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,044: Line 1,044:


=={{header|Tiny BASIC}}==
=={{header|Tiny BASIC}}==
<lang tinybasic> LET A = 1
<syntaxhighlight lang="tinybasic"> LET A = 1
10 LET A = A + 2
10 LET A = A + 2
IF A > 5499 THEN END
IF A > 5499 THEN END
Line 1,065: Line 1,065:
LET I = I + 1
LET I = I + 1
IF I*I <= P THEN GOTO 110
IF I*I <= P THEN GOTO 110
RETURN</lang>
RETURN</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
<syntaxhighlight lang="ecmascript">import "/math" for Int
import "/fmt" for Fmt
import "/fmt" for Fmt


Line 1,082: Line 1,082:
}
}
for (triple in triples) Fmt.print("$,6d", triple)
for (triple in triples) Fmt.print("$,6d", triple)
System.print("\nFound %(triples.count) such prime triplets.")</lang>
System.print("\nFound %(triples.count) such prime triplets.")</syntaxhighlight>


{{out}}
{{out}}
Line 1,135: Line 1,135:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number
<syntaxhighlight lang="xpl0">func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
int N, I;
[if N <= 1 then return false;
[if N <= 1 then return false;
Line 1,160: Line 1,160:
Text(0, " prime triplets found below 5500.
Text(0, " prime triplets found below 5500.
");
");
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}