Palindromic primes: Difference between revisions

m
(Added S-BASIC example)
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.
{{libheader|ALGOL 68-primes}}
<syntaxhighlight lang="algol68">BEGIN # find primes that are palendromic in base 10 #
INT max prime = 999;
# sieve the primes to max prime #
PR read "primes.incl.a68" PR
[]BOOL prime = PRIMESIEVE max prime;
# print the palendromic primes in the base 10 #
# all 1 digit primes are palindromic #
FOR# nthe TOonly 9palindromic DO2 IFdigit prime[numbers nare ]multiples THENof print(11 ( " ", whole( n, 0 ) ) ) FI OD; #
# so 11 is the only palindromicpossible 2 digit numberspalindromic prime are multiples of 11 #
FOR n TO 11 DO IF prime[ 11n ] THEN print( ( " 11", whole( n, 0 ) ) ) FI OD;
# so 11 is the only possible 2 digit palindromic prime #
# three digit numbers, the first and last digits must be odd #
IF prime[ 11 ] THEN print( ( " 11" ) ) FI;
# threeand digitcannot numbers,be 5 (as the firstnumber would be divisible by 5) and last digits must be odd #
# and cannot be 5 (as the number would be divisible by 5) #
FOR fl BY 2 TO 9 DO
IF fl /= 5 THEN
Line 105 ⟶ 104:
OD;
print( ( newline ) )
END
END</syntaxhighlight>
{{out}}
<pre>
3,028

edits