Twin primes: Difference between revisions

→‎{{header|ALGOL 68}}: Obvious optimisation and remove unnecessary comments
(C++ program allows limits to be specified on command line)
(→‎{{header|ALGOL 68}}: Obvious optimisation and remove unnecessary comments)
Line 44:
PROC sieve = ( REF[]BOOL s )VOID:
BEGIN
# start with everything flagged as prime #
FOR i TO UPB s DO s[ i ] := TRUE OD;
# sieve out the non-primes #
s[ 1 ] := FALSE;
FOR i FROM 2 TO ENTIER sqrt( UPB s ) DO
Line 63 ⟶ 61:
# note 2 cannot be one of the primes in a twin prime pair, so we start at 3 #
INT twin count := 0;
FOR p FROM 3 BY 2 TO max number DO IF primes[ p ] AND primes[ p - 2 ] THEN twin count +:= 1 FI OD;
print( ( "twin prime pairs below ", whole( max number, 0 ), ": ", whole( twin count, 0 ), newline ) )
END</lang>
3,048

edits