Anonymous user
Piprimes: Difference between revisions
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. */
if cols>0 then say ' index │'center(
if cols>0 then say '───────┼'center("" ,
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
c= commas(pips) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) )
if j//cols\==0
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 '
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= 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
|