Sum of two adjacent numbers are primes: Difference between revisions

→‎{{header|ALGOL 68}}: Simplify as per the Phix sample
(→ "Show on this page the first 20 prime sums of two consecutive integers")
(→‎{{header|ALGOL 68}}: Simplify as per the Phix sample)
Line 61:
 
=={{header|ALGOL 68}}==
Using Pete Lomax's observation that all odd primes are n + n+1 for some n - see [[#Phix]]
{{libheader|ALGOL 68-primes}}
<syntaxhighlight lang="algol68">BEGIN # find the first 20 primes which are n + ( n + 1 ) for some n #
Line 66 ⟶ 67:
[]BOOL prime = PRIMESIEVE 200; # should be enough primes #
INT p count := 0;
FOR np FROM 3 BY 2 WHILE p count < 20 DO
INT n1 = n + 1;
INT p = n + n1;
IF prime[ p ] THEN
INT pn = np +OVER n12;
INT n1 = n + 1;
p count +:= 1;
print( ( whole( n, -2 ), " + ", whole( n1, -2 ), " = ", whole( p, -3 ), newline ) )
FI
OD
END
END</syntaxhighlight>
{{out}}
<pre>
3,038

edits