Piprimes: Difference between revisions

490 bytes added ,  2 years ago
m
→‎{{header|REXX}}: changed whitespace and comments, added a foot separator for the output.
(Added Sidef)
m (→‎{{header|REXX}}: changed whitespace and comments, added a foot separator for the output.)
Line 465:
call genP /*build array of semaphores for primes.*/
w= 10 /*width of a number in any column. */
@pipstitle= ' number of primes that are (for all N) ≤ prime(22) which is ' commas(@.hi)
if cols>0 then say ' index │'center(@pipstitle, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
idx= 1 /*initialize the index of output lines.*/
$=; pips= 0 /*a list of piPrimes numbers (so far). */
do j=1 for @.hi-1 /*gen list of piPrime numbers<prime(hi)*/
if !.j then pips= pips + 1 /*Is J prime? Then bump pips number.*/
if cols==<0 then iterate then iterate /*Build the list (to be shown later)? */
c= commas(pips) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) ) /*add a Frobenius #──►list, allow big #*/
if j//cols\==0 then iterate /*have we populated a line of output? */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
idx= idx + cols /*bump the index count for the output*/
Line 481:
 
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' commas(j-1)", the" title /*display the foot separator for @pipsoutput*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 501 ⟶ 502:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 514 ⟶ 515:
61 │ 18 18 18 18 18 18 19 19 19 19
71 │ 20 20 21 21 21 21 21 21
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 
Found 78, the number of primes that are (for all N) ≤ prime(22) which is 79