Piprimes: Difference between revisions
Content added Content deleted
(Added Sidef) |
m (→{{header|REXX}}: changed whitespace and comments, added a foot separator for the output.) |
||
Line 465: | Line 465: | ||
call genP /*build array of semaphores for primes.*/ |
call genP /*build array of semaphores for primes.*/ |
||
w= 10 /*width of a number in any column. */ |
w= 10 /*width of a number in any column. */ |
||
title= ' number of primes that are (for all N) ≤ prime(22) which is ' commas(@.hi) |
|||
if cols>0 then say ' index │'center( |
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), '─') |
||
idx= 1 /*initialize the index of output lines.*/ |
idx= 1 /*initialize the index of output lines.*/ |
||
$=; pips= 0 /*a list of piPrimes numbers (so far). */ |
$=; pips= 0 /*a list of piPrimes numbers (so far). */ |
||
do j=1 for @.hi-1 /*gen list of piPrime numbers<prime(hi)*/ |
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 !.j then pips= pips + 1 /*Is J prime? Then bump pips number.*/ |
||
if cols |
if cols<0 then iterate /*Build the list (to be shown later)? */ |
||
c= commas(pips) /*maybe add commas to the number. */ |
c= commas(pips) /*maybe add commas to the number. */ |
||
$= $ right(c, max(w, length(c) ) ) |
$= $ right(c, max(w, length(c) ) ) /*add a Frobenius #──►list, allow big #*/ |
||
if j//cols\==0 |
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). */ |
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */ |
||
idx= idx + cols /*bump the index count for the output*/ |
idx= idx + cols /*bump the index count for the output*/ |
||
Line 481: | Line 481: | ||
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
||
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─') |
|||
say |
say |
||
say 'Found ' |
say 'Found ' commas(j-1)", the" title /*display the foot separator for output*/ |
||
exit 0 /*stick a fork in it, we're all done. */ |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
Line 501: | Line 502: | ||
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> |
||
Line 514: | Line 515: | ||
61 │ 18 18 18 18 18 18 19 19 19 19 |
61 │ 18 18 18 18 18 18 19 19 19 19 |
||
71 │ 20 20 21 21 21 21 21 21 |
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 |
Found 78, the number of primes that are (for all N) ≤ prime(22) which is 79 |