Primes whose first and last number is 3: Difference between revisions

Content added Content deleted
m (to 10000)
(→‎{{header|ALGOL 68}}: Use ALGOL 68-primes)
Line 13: Line 13:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{Trans|ALGOL W}} With added stretch goal. As with the Go and other samples, generates the candidate sequence.
{{Trans|ALGOL W}} With added stretch goal. As with the Go and other samples, generates the candidate sequence.
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find some primes whose first and last digits are 3 #
<lang algol68>BEGIN # find some primes whose first and last digits are 3 #
INT max prime = 1 000 000; # largest number to consider #
INT max prime = 1 000 000; # largest number to consider #
# sieve the primes to max prime #
# sieve the primes to max prime #
PR read "primes.incl.a68" PR
[ 1 : max prime ]BOOL prime;
prime[ 1 ] := FALSE; prime[ 2 ] := TRUE;
[]BOOL prime = PRIMESIEVE max prime;
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 prime ) DO
IF prime[ i ] THEN FOR s FROM i * i BY i + i TO UPB prime DO prime[ s ] := FALSE OD FI
OD;
INT p3count := 0;
INT p3count := 0;
# prints n, if it is prime, handles newlines #
# prints n, if it is prime, handles newlines #
Line 30: Line 26:
IF ( p3count +:= 1 ) MOD 12 = 0 THEN print( ( newline ) ) FI
IF ( p3count +:= 1 ) MOD 12 = 0 THEN print( ( newline ) ) FI
FI # p #;
FI # p #;
# find 1, 2, 3 and 4 digit 3x3 primes #
# find 3x3 primes #
p( 3 ); p( 33 ); FOR i FROM 0 BY 10 TO 90 DO p( 303 + i ) OD; FOR i FROM 0 BY 10 TO 990 DO p( 3003 + i ) OD;
p( 3 ); p( 33 ); # a & 2 digit 3x3 primes #
FOR i FROM 0 BY 10 TO 90 DO p( 303 + i ) OD; # 3 digit 3x3 primes #
FOR i FROM 0 BY 10 TO 990 DO p( 3003 + i ) OD; # 4 digit 3x3 primes #
# 5 and 6 digit 3x3 primes #
# 5 and 6 digit 3x3 primes #
FOR i FROM 0 BY 10 TO 9 990 DO IF prime[ 30 003 + i ] THEN p3count +:= 1 FI OD;
FOR i FROM 0 BY 10 TO 9 990 DO IF prime[ 30 003 + i ] THEN p3count +:= 1 FI OD;