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

→‎{{header|ALGOL 68}}: Added stretch goal
(Added Algol 68)
(→‎{{header|ALGOL 68}}: Added stretch goal)
Line 14:
{{Trans|ALGOL W}} As with the Go and other samples, generates the candidate sequence.
<lang algol68>BEGIN # find some primes whose first and last digits are 3 #
INT max prime = 40001 000 000; # largest number to consider #
# sieve the primes to max prime #
[ 1 : max prime ]BOOL prime;
Line 30:
IF ( p3count +:= 1 ) MOD 12 = 0 THEN print( ( newline ) ) FI
FI # p #;
# find 1, 2, 3 and 34 digit 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;
# 45 and 6 digit 3x3 primes #
FOR i FROM 0 BY 10 TO 9 990 DO p(IF 3003prime[ 30 003 + i )] THEN p3count +:= 1 FI OD;
FOR i FROM 0 BY 10 TO 99 990 DO IF prime[ 300 003 + i ] THEN p3count +:= 1 FI OD;
print( ( newline, "Found ", whole( p3count, 0 ), " ""3x3"" primes below 1000000", newline ) )
END</lang>
{{out}}
Line 40 ⟶ 42:
3343 3373 3413 3433 3463 3533 3583 3593 3613 3623 3643 3673
3733 3793 3803 3823 3833 3853 3863 3923 3943
Found 2251 "3x3" primes below 1000000
</pre>
 
3,047

edits