Emirp primes: Difference between revisions

→‎{{header|ALGOL 68}}: Use ALGOL 68-primes
(→‎{{header|ALGOL 68}}: Use ALGOL 68-primes)
Line 109:
Uses Algol 68G specific argc and argv procedures to access to command line.
Allows the user to specify the from and to range values or ordinals on the command line. The sieve size can also be specified. As suggested by the Fortran sample, from = to is treated as a special case for labeling the output.
{{libheader|ALGOL 68-primes}}
<lang algol68># sieve of Eratosthenes: sets s[i] to TRUE if i is prime, FALSE otherwise #
<lang algol68># parse the command line - ignore errors #
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
IF s[ i ] THEN FOR p FROM i * i BY i TO UPB s DO s[ p ] := FALSE OD FI
OD
END # sieve # ;
 
# parse the command line - ignore errors #
INT emirp from := 1; # lowest emirp required #
INT emirp to := 10; # highest emirp required #
Line 153 ⟶ 142:
 
# construct a sieve of primes up to the maximum number required for the task #
PR read "primes.incl.a68" PR
[ 1 : max number ]BOOL is prime;
sieve([]BOOL is prime )= PRIMESIEVE max number;
 
# return TRUE if p is an emirp, FALSE otherwise #
3,036

edits