Palindromic primes: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed the GENP subroutine.) |
(→{{header|ALGOL 68}}: Use ALGOL 68-primes) |
||
Line 8: | Line 8: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
Generates the palindrmic 3 digit numbers and uses the observations that all 1 digit primes are palindromic and that for 2 digit numbers, only multiples of 11 are palindromic and hence 11 is the only two digit palindromic prime. |
Generates the palindrmic 3 digit numbers and uses the observations that all 1 digit primes are palindromic and that for 2 digit numbers, only multiples of 11 are palindromic and hence 11 is the only two digit palindromic prime. |
||
{{libheader|ALGOL 68-primes}} |
|||
<lang algol68>BEGIN # find primes that are palendromic in base 10 # |
<lang algol68>BEGIN # find primes that are palendromic in base 10 # |
||
INT max prime = 999; |
INT max prime = 999; |
||
# sieve the primes to max prime # |
# sieve the primes to max prime # |
||
PR read "primes.incl.a68" PR |
|||
[ 1 : max prime ]BOOL prime; |
|||
[]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; |
|||
# print the palendromic primes in the base 10 # |
# print the palendromic primes in the base 10 # |
||
# all 1 digit primes are palindromic # |
# all 1 digit primes are palindromic # |