Anonymous user
Palindromic primes: Difference between revisions
m
→{{header|REXX}}: changed the title for the output to reflect that the palindromic primes are in base ten.
m (→{{header|REXX}}: changed the title for the output to reflect that the palindromic primes are in base ten.) |
|||
Line 577:
=={{header|REXX}}==
<lang rexx>/*REXX program finds and displays palindromic primes in base ten for all N < 1,000.
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/
Line 583:
call genP /*build array of semaphores for primes.*/
w= max(8, length( commas(hi) ) ) /*max width of a number in any column. */
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("", 1 + cols*(w+1), '─')
finds= 0; idx= 1 /*define # of palindromic primes & idx.*/
$= /*a list of palindromic primes (so far)*/
do j=1 for hi; if \!.j then iterate /*Is this number not prime? Then skip.*/ /* ◄■■■■■■■■ a filter. */
if j\==reverse(j) then iterate /*Not a palindromic prime? " " */ /* ◄■■■■■■■■ a filter. */
finds= finds + 1 /*bump the number of palindromic primes*/
if cols<0 then iterate /*Build the list (to be shown later)? */
Line 621:
{{out|output|text= when using the default inputs:}}
<pre>
index │ palindromic primes in base
───────┼───────────────────────────────────────────────────────────────────────────────────────────
1
11
───────┴───────────────────────────────────────────────────────────────────────────────────────────
Found 20 palindromic primes in base ten that are < 1,000
</pre>
{{out|output|text= when using the input of: <tt> 100000 </tt>}}
<pre>
index │ palindromic primes in base
───────┼───────────────────────────────────────────────────────────────────────────────────────────
1
11
21
31
41
51
61
71
81
91
101
111
───────┴───────────────────────────────────────────────────────────────────────────────────────────
Found 113 palindromic primes in base ten that are < 100,000
</pre>
|