Palindromic primes: Difference between revisions
Content added Content deleted
(Added S-BASIC example) |
m (→{{header|ALGOL 68}}: tweak) |
||
Line 80: | Line 80: | ||
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}} |
{{libheader|ALGOL 68-primes}} |
||
<syntaxhighlight lang="algol68">BEGIN # find primes that are palendromic in base 10 # |
<syntaxhighlight 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 |
PR read "primes.incl.a68" PR |
||
[]BOOL prime = PRIMESIEVE max prime; |
[]BOOL prime = PRIMESIEVE max prime; |
||
# 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 # |
||
# the only palindromic 2 digit numbers are multiples of 11 # |
|||
# the only |
# so 11 is the only possible 2 digit palindromic prime # |
||
⚫ | |||
# so 11 is the only possible 2 digit palindromic prime # |
|||
# three digit numbers, the first and last digits must be odd # |
|||
⚫ | |||
# |
# and cannot be 5 (as the number would be divisible by 5) # |
||
# and cannot be 5 (as the number would be divisible by 5) # |
|||
FOR fl BY 2 TO 9 DO |
FOR fl BY 2 TO 9 DO |
||
IF fl /= 5 THEN |
IF fl /= 5 THEN |
||
Line 105: | Line 104: | ||
OD; |
OD; |
||
print( ( newline ) ) |
print( ( newline ) ) |
||
END |
|||
</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |