Triplet of three numbers: Difference between revisions

→‎{{header|ALGOL 68}}: Use ALGOL 68-primes
m (→‎{{header|REXX}}: added filter comments, optimized the GENP subroutine.)
(→‎{{header|ALGOL 68}}: Use ALGOL 68-primes)
Line 7:
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find numbers n where n-1, n+3 and n+5 are prime #
INT max number = 6000;
# sieve the primes up to maxthe maximum number for the task #
PR read "primes.incl.a68" PR
[ 1 : max number ]BOOL prime;
prime[ 1 ] := FALSE;BOOL prime[ 2= ] :=PRIMESIEVE TRUE6000;
FOR i FROM 3 BY 2 TO UPB prime DO prime[ i ] := TRUE OD;
FOR i FROM 4 BY 2 TO UPB prime DO prime[ i ] := FALSE OD;
FOR i FROM 3 BY 2 TO ENTIER sqrt( max number ) DO
IF prime[ i ] THEN FOR s FROM i * i BY i + i TO UPB prime DO prime[ s ] := FALSE OD FI
OD;
# returns a string represention of n #
OP TOSTRING = ( INT n )STRING: whole( n, 0 );
Line 22 ⟶ 17:
# 2 is clearly not a member of the required numbers, so we start at 3 #
INT n count := 0;
FOR n FROM 3 TO maxUPB numberprime - 5 DO
IF prime[ n - 1 ] AND prime[ n + 3 ] AND prime[ n + 5 ] THEN
print( ( " (", TOSTRING n, " | ", TOSTRING ( n - 1 ), ", ", TOSTRING ( n + 3 ), ", ", TOSTRING ( n + 5 ), ")" ) );
3,028

edits