Palindromic primes: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed some comments.) |
m (→{{header|REXX}}: added comments.) |
||
Line 478: | Line 478: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program finds and displays palindromic primes for all N < |
<lang rexx>/*REXX program finds and displays palindromic primes for all N < 1,000. */ |
||
parse arg hi cols . /*obtain optional argument from the CL.*/ |
parse arg hi cols . /*obtain optional argument from the CL.*/ |
||
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/ |
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/ |
||
Line 484: | Line 484: | ||
call genP /*build array of semaphores for primes.*/ |
call genP /*build array of semaphores for primes.*/ |
||
w= max(8, length( commas(hi) ) ) /*max width of a number in any column. */ |
w= max(8, length( commas(hi) ) ) /*max width of a number in any column. */ |
||
title= ' palindromic primes that are < ' |
title= ' palindromic primes that are < ' commas(hi) |
||
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) ) |
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) ) |
||
if cols>0 then say '───────┼'center("" |
if cols>0 then say '───────┼'center("", 1 + cols*(w+1), '─') |
||
finds= 0; idx= 1 /*define # of palindromic primes & idx.*/ |
finds= 0; idx= 1 /*define # of palindromic primes & idx.*/ |
||
$= /*a list of palindromic primes (so far)*/ |
$= /*a list of palindromic primes (so far)*/ |
||
do j=1 for hi |
do j=1 for hi; if \!.j then iterate /*Is this number not prime? Then skip.*/ /* ◄■■■■■■■■ a filter. */ |
||
if \ |
if j\==reverse(j) then iterate /*Not a palindromic prime? " " */ /* ◄■■■■■■■■ a filter. */ |
||
if j\==reverse(j) then iterate /*Not a palindromic prime? " " */ |
|||
finds= finds + 1 /*bump the number of palindromic primes*/ |
finds= finds + 1 /*bump the number of palindromic primes*/ |
||
if cols<0 |
if cols<0 then iterate /*Build the list (to be shown later)? */ |
||
$= $ right( commas(j), w) /*add a palindromic prime |
$= $ right( commas(j), w) /*add a palindromic prime $ list.*/ |
||
if finds//cols\==0 |
if finds//cols\==0 then iterate /*have we populated a line of output? */ |
||
say center(idx, 7)' |
say center(idx, 7)'|' substr($, 2); $= /*display what we have so for (cols). */ |
||
idx= idx + cols /*bump the index count for the output*/ |
idx= idx + cols /*bump the index count for the output*/ |
||
end /*j*/ |
end /*j*/ |
||
if $\=='' then say center(idx, 7) |
if $\=='' then say center(idx, 7)'|' substr($, 2) /*possibly display residual output.*/ |
||
if cols>0 then say '───────┴'center("" |
if cols>0 then say '───────┴'center("", 1 + cols*(w+1), '─') |
||
say |
say |
||
say 'Found ' commas(finds) title |
say 'Found ' commas(finds) title |
||
Line 522: | Line 521: | ||
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
||
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */ |
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */ |
||
end /*j*/; return</lang> |
end /*j*/; return</lang> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |