Special neighbor primes: Difference between revisions

Added PL/0
m (→‎{{header|ALGOL 68}}: Added link to the Neighbour primes task)
(Added PL/0)
Line 671:
</pre>
 
 
=={{header|PL/0}}==
PL/0 can only output a single integer per line, so to avoid confusing output, this sample just shows the first prime of each pair.
<br>
This is almost identical to the [[Neighbour primes#PL/0|PL/0 sample in the Neighbour primes task]]
<syntaxhighlight lang="pascal">
var n, p1, p2, prime;
procedure isnprime;
var p;
begin
prime := 1;
if n < 2 then prime := 0;
if n > 2 then begin
prime := 0;
if odd( n ) then prime := 1;
p := 3;
while p * p <= n * prime do begin
if n - ( ( n / p ) * p ) = 0 then prime := 0;
p := p + 2;
end
end
end;
begin
p1 := 3;
p2 := 5;
while p2 < 100 do begin
n := ( p1 + p2 ) - 1;
call isnprime;
if prime = 1 then ! p1;
n := p2 + 2;
call isnprime;
while prime = 0 do begin
n := n + 2;
call isnprime;
end;
p1 := p2;
p2 := n;
end
end.
</syntaxhighlight>
{{out}}
<pre>
3
5
7
11
13
19
29
31
41
43
61
67
73
</pre>
 
=={{header|Python}}==
Line 712 ⟶ 768:
67 71 137
73 79 151</pre>
 
 
=={{header|Raku}}==
3,032

edits