Neighbour primes: Difference between revisions

Content added Content deleted
(Neighbour primes in various BASIC dialents)
m (syntax highlighting fixup automation)
Line 7: Line 7:


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
<lang algolw>begin % find some primes where ( p*q ) + 2 is also a prime ( where p and q are adjacent primes ) %
<syntaxhighlight lang="algolw">begin % find some primes where ( p*q ) + 2 is also a prime ( where p and q are adjacent primes ) %
% sets p( 1 :: n ) to a sieve of primes up to n %
% sets p( 1 :: n ) to a sieve of primes up to n %
procedure sieve ( logical array p( * ) ; integer value n ) ;
procedure sieve ( logical array p( * ) ; integer value n ) ;
Line 46: Line 46:
write( i_w := 1, s_w := 0, "Found ", pCount, " neighbour primes up to 500" )
write( i_w := 1, s_w := 0, "Found ", pCount, " neighbour primes up to 500" )
end
end
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 54: Line 54:


=={{header|AppleScript}}==
=={{header|AppleScript}}==
<lang applescript>on isPrime(n)
<syntaxhighlight lang="applescript">on isPrime(n)
if (n < 6) then return ((n > 1) and (n is not 4))
if (n < 6) then return ((n > 1) and (n is not 4))
if ((n mod 2 = 0) or (n mod 3 = 0) or (n mod 5 = 0)) then return false
if ((n mod 2 = 0) or (n mod 3 = 0) or (n mod 5 = 0)) then return false
Line 82: Line 82:
end neighbourPrimes
end neighbourPrimes


neighbourPrimes(499)</lang>
neighbourPrimes(499)</syntaxhighlight>


{{output}}
{{output}}
<lang applescript>{3, 5, 7, 13, 19, 67, 149, 179, 229, 239, 241, 269, 277, 307, 313, 397, 401, 419, 439, 487}</lang>
<syntaxhighlight lang="applescript">{3, 5, 7, 13, 19, 67, 149, 179, 229, 239, 241, 269, 277, 307, 313, 397, 401, 419, 439, 487}</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>primesUpTo500: select 1..500 => prime?
<syntaxhighlight lang="rebol">primesUpTo500: select 1..500 => prime?


print [pad "p" 5 pad "q" 4 pad "p*q+2" 7]
print [pad "p" 5 pad "q" 4 pad "p*q+2" 7]
Line 103: Line 103:
]
]
i: i + 1
i: i + 1
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 131: Line 131:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f NEIGHBOUR_PRIMES.AWK
# syntax: GAWK -f NEIGHBOUR_PRIMES.AWK
BEGIN {
BEGIN {
Line 162: Line 162:
return(1)
return(1)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 193: Line 193:
=={{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 215: Line 215:
print p; chr(9); q; chr(9); 2+p*q
print p; chr(9); q; chr(9); 2+p*q
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 254: Line 254:
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>sub isPrime(v)
<syntaxhighlight lang="yabasic">sub isPrime(v)
if v < 2 then return False : fi
if v < 2 then return False : fi
if mod(v, 2) = 0 then return v = 2 : fi
if mod(v, 2) = 0 then return v = 2 : fi
Line 279: Line 279:
print p, chr$(9), q, chr$(9), 2+p*q
print p, chr$(9), q, chr$(9), 2+p*q
next p
next p
end</lang>
end</syntaxhighlight>




=={{header|C#|CSharp}}==
=={{header|C#|CSharp}}==
How about some other offsets besides <code>+ 2</code> ?
How about some other offsets besides <code>+ 2</code> ?
<lang fsharp>using System; using System.Collections.Generic;
<syntaxhighlight lang="fsharp">using System; using System.Collections.Generic;
using System.Linq; using static System.Console; using System.Collections;
using System.Linq; using static System.Console; using System.Collections;


Line 313: Line 313:
if (!flags[j]) { yield return j;
if (!flags[j]) { yield return j;
for (int k = sq, i=j<<1; k<=lim; k += i) flags[k] = true; }
for (int k = sq, i=j<<1; k<=lim; k += i) flags[k] = true; }
for (; j <= lim; j += 2) if (!flags[j]) yield return j; } }</lang>
for (; j <= lim; j += 2) if (!flags[j]) yield return j; } }</syntaxhighlight>
{{out}}
{{out}}
<pre>Multiply two consecutive prime numbers, add an even number, see if the result is a prime number (up to a limit).
<pre>Multiply two consecutive prime numbers, add an even number, see if the result is a prime number (up to a limit).
Line 361: Line 361:
=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<lang fsharp>
<syntaxhighlight lang="fsharp">
// Nigel Galloway. April 13th., 2021
// Nigel Galloway. April 13th., 2021
primes32()|>Seq.pairwise|>Seq.takeWhile(fun(n,_)->n<500)|>Seq.filter(fun(n,g)->isPrime(n*g+2))|>Seq.iter(fun(n,g)->printfn "%d*%d=%d" n g (n*g+2))
primes32()|>Seq.pairwise|>Seq.takeWhile(fun(n,_)->n<500)|>Seq.filter(fun(n,g)->isPrime(n*g+2))|>Seq.iter(fun(n,g)->printfn "%d*%d=%d" n g (n*g+2))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 391: Line 391:
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
{{works with|Factor|0.99 2021-02-05}}
<lang factor>USING: formatting io kernel math math.primes ;
<syntaxhighlight lang="factor">USING: formatting io kernel math math.primes ;


"p q p*q+2" print
"p q p*q+2" print
Line 399: Line 399:
[ 3dup "%-4d %-4d %-6d\n" printf ] when
[ 3dup "%-4d %-4d %-6d\n" printf ] when
drop nip dup next-prime
drop nip dup next-prime
] while 2drop</lang>
] while 2drop</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 427: Line 427:
=={{header|Fermat}}==
=={{header|Fermat}}==
{{trans|PARI/GP}}
{{trans|PARI/GP}}
<lang fermat>for i = 1 to 95 do if Isprime(2+Prime(i)*Prime(i+1)) then !!Prime(i) fi od</lang>
<syntaxhighlight lang="fermat">for i = 1 to 95 do if Isprime(2+Prime(i)*Prime(i+1)) then !!Prime(i) fi od</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>#include "isprime.bas"
<syntaxhighlight lang="freebasic">#include "isprime.bas"


dim as uinteger q
dim as uinteger q
Line 444: Line 444:
if not isprime( 2 + p*q ) then continue for
if not isprime( 2 + p*q ) then continue for
print p,q,2+p*q
print p,q,2+p*q
next p</lang>
next p</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 482: Line 482:
{{trans|Wren}}
{{trans|Wren}}
{{libheader|Go-rcu}}
{{libheader|Go-rcu}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 501: Line 501:
rcu.PrintTable(nprimes, 10, 3, false)
rcu.PrintTable(nprimes, 10, 3, false)
fmt.Println("\nFound", len(nprimes), "such primes.")
fmt.Println("\nFound", len(nprimes), "such primes.")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 517: Line 517:


This entry uses `is_prime` as defined at [[Erd%C5%91s-primes#jq]].
This entry uses `is_prime` as defined at [[Erd%C5%91s-primes#jq]].
<lang jq>def next_prime:
<syntaxhighlight lang="jq">def next_prime:
if . == 2 then 3
if . == 2 then 3
else first(range(.+2; infinite; 2) | select(is_prime))
else first(range(.+2; infinite; 2) | select(is_prime))
Line 537: Line 537:
| .p = $np )
| .p = $np )
| select(.emit).emit
| select(.emit).emit
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 563: Line 563:


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


isneiprime(known) = isprime(known) && isprime(known * nextprime(known + 1) + 2)
isneiprime(known) = isprime(known) && isprime(known * nextprime(known + 1) + 2)
println(filter(isneiprime, primes(500)))
println(filter(isneiprime, primes(500)))
</lang>{{out}}<pre>[3, 5, 7, 13, 19, 67, 149, 179, 229, 239, 241, 269, 277, 307, 313, 397, 401, 419, 439, 487]</pre>
</syntaxhighlight>{{out}}<pre>[3, 5, 7, 13, 19, 67, 149, 179, 229, 239, 241, 269, 277, 307, 313, 397, 401, 419, 439, 487]</pre>


=={{header|Ksh}}==
=={{header|Ksh}}==
<lang ksh>
<syntaxhighlight lang="ksh">
#!/bin/ksh
#!/bin/ksh


Line 623: Line 623:
np=$(_neighbourprime ${i} parr)
np=$(_neighbourprime ${i} parr)
(( np > 0 )) && printf "%3d %3d %6d\n" ${parr[i]} ${parr[i+1]} ${np}
(( np > 0 )) && printf "%3d %3d %6d\n" ${parr[i]} ${parr[i+1]} ${np}
done</lang>
done</syntaxhighlight>
{{out}}<pre>
{{out}}<pre>
p q p*q+2
p q p*q+2
Line 650: Line 650:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>p = Prime@Range@PrimePi[499];
<syntaxhighlight lang="mathematica">p = Prime@Range@PrimePi[499];
Select[p, PrimeQ[# NextPrime[#] + 2] &]</lang>
Select[p, PrimeQ[# NextPrime[#] + 2] &]</syntaxhighlight>
{{out}}
{{out}}
<pre>{3, 5, 7, 13, 19, 67, 149, 179, 229, 239, 241, 269, 277, 307, 313, 397, 401, 419, 439, 487}</pre>
<pre>{3, 5, 7, 13, 19, 67, 149, 179, 229, 239, 241, 269, 277, 307, 313, 397, 401, 419, 439, 487}</pre>


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


const
const
Line 686: Line 686:
if (p * q + 2).isPrime:
if (p * q + 2).isPrime:
echo &"{p:3} {q:3} {p*q+2:6}"
echo &"{p:3} {q:3} {p*q+2:6}"
p = q</lang>
p = q</syntaxhighlight>


{{out}}
{{out}}
Line 712: Line 712:
=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
Cheats a little in the sense that it requires knowing the 95th prime is 499 beforehand.
Cheats a little in the sense that it requires knowing the 95th prime is 499 beforehand.
<lang parigp>for(i=1, 95, if(isprime(2+prime(i)*prime(i+1)),print(prime(i))))</lang>
<syntaxhighlight lang="parigp">for(i=1, 95, if(isprime(2+prime(i)*prime(i+1)),print(prime(i))))</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;
use ntheory <next_prime is_prime>;
use ntheory <next_prime is_prime>;
Line 725: Line 725:
printf "%3d%5d%8d\n", $p, $q, $p*$q+2 if is_prime $p*$q+2;
printf "%3d%5d%8d\n", $p, $q, $p*$q+2 if is_prime $p*$q+2;
$p = $q;
$p = $q;
} until $p >= 500;</lang>
} until $p >= 500;</syntaxhighlight>
{{out}}
{{out}}
<pre> 3 5 17
<pre> 3 5 17
Line 749: Line 749:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">np</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: #7060A8;">get_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)*</span><span style="color: #7060A8;">get_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">2</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;">np</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: #7060A8;">get_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)*</span><span style="color: #7060A8;">get_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">N</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">500</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">N</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">500</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;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</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;">N</span><span style="color: #0000FF;">),</span><span style="color: #000000;">np</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">get_prime</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">sprint</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;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</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;">N</span><span style="color: #0000FF;">),</span><span style="color: #000000;">np</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">get_prime</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">sprint</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 such primes: %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;">5</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 such primes: %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;">5</span><span style="color: #0000FF;">),</span><span style="color: #008000;">", "</span><span style="color: #0000FF;">)})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 762: Line 762:


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


def isPrime(n):
def isPrime(n):
Line 782: Line 782:
if not isPrime(2 + p*q):
if not isPrime(2 + p*q):
continue
continue
print(p, "\t", q, "\t", 2+p*q)</lang>
print(p, "\t", q, "\t", 2+p*q)</syntaxhighlight>
{{out}}
{{out}}
<pre>p q pq+2
<pre>p q pq+2
Line 809: Line 809:


=={{header|Raku}}==
=={{header|Raku}}==
<lang perl6>my @primes = grep &is-prime, ^Inf;
<syntaxhighlight lang="raku" line>my @primes = grep &is-prime, ^Inf;
my $last_p = @primes.first: :k, * >= 500;
my $last_p = @primes.first: :k, * >= 500;
my $last_q = $last_p + 1;
my $last_q = $last_p + 1;
Line 818: Line 818:
.grep( *.[2].is-prime );
.grep( *.[2].is-prime );


say .fmt('%6d') for @cousins;</lang>
say .fmt('%6d') for @cousins;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 845: Line 845:
=={{header|REXX}}==
=={{header|REXX}}==
'''Neighbor''' primes can also be spelled '''neighbour''' primes.
'''Neighbor''' primes can also be spelled '''neighbour''' primes.
<lang rexx>/*REXX program finds neighbor primes: P, Q, P*Q+2 are primes, and P < some specified N.*/
<syntaxhighlight lang="rexx">/*REXX program finds neighbor primes: P, Q, P*Q+2 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= 500 /*Not specified? Then use the default.*/
if hi=='' | hi=="," then hi= 500 /*Not specified? Then use the default.*/
Line 889: Line 889:
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 902: Line 902:


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


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>500.primes.grep {|p| p * p.next_prime + 2 -> is_prime }.say</lang>
<syntaxhighlight lang="ruby">500.primes.grep {|p| p * p.next_prime + 2 -> is_prime }.say</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 976: Line 976:
{{libheader|Wren-seq}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
<syntaxhighlight lang="ecmascript">import "/math" for Int
import "/seq" for Lst
import "/seq" for Lst
import "/fmt" for Fmt
import "/fmt" for Fmt
Line 988: Line 988:
}
}
for (chunk in Lst.chunks(nprimes, 10)) Fmt.print("$3d", chunk)
for (chunk in Lst.chunks(nprimes, 10)) Fmt.print("$3d", chunk)
System.print("\nFound %(nprimes.count) such primes.")</lang>
System.print("\nFound %(nprimes.count) such primes.")</syntaxhighlight>


{{out}}
{{out}}
Line 1,000: Line 1,000:


=={{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,025: Line 1,025:
Text(0, " neighbour primes found below 500.
Text(0, " neighbour primes found below 500.
");
");
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}