Cubic special primes: Difference between revisions

m
→‎{{header|REXX}}: simplified code, added a foot sep, changed whitespace and comments.
(Added Algol W)
m (→‎{{header|REXX}}: simplified code, added a foot sep, changed whitespace and comments.)
Line 400:
call genP /*build array of semaphores for primes.*/
w= 10 /*width of a number in any column. */
@cbptitle= 'the smallest primes < ' commas(hi) " such that the" ,
'difference of successive terma are the smallest cubic numbers'
if cols>0 then say ' index │'center(@cbp title, 1 + cols*(w+1) ) /*display the title.*/
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─') /* " , " 1 + colssep.*(w+1), '─')/
cbpfound= 0; idx= 1 /*initialize number of cbp and index.*/
op= 1
$= /*a list of nicecubic primes (so far). */
do j=0 by 0
do k=1 until !.np; np= op + k**3 /*find the next square + oldPrime.*/
if np>= hiop + k**3 then leave j /*Isfind newPrimethe toonext big?cube plus Thenthe quitoldPrime.*/
end if np>= hi then leave j /*kIs newPrime too big? Then quit. */
cbp= cbp + 1 end /*bump the number of cbp's. k*/
found= found + 1 /*bump number of primes of this type. */
op= np /*assign the newPrime to the oldPrime*/
if cols==<0 then iterate then iterate /*Build the list (to be shown later)? */
c= commas(np) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) ) /*add a nicecubic prime ──► listprime──►list, allow big#.*/
if cbpfound//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 422 ⟶ 423:
 
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─') /*display foot sep. */
say
say 'Found ' commas(cbpfound) " of " @cbp title
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 450 ⟶ 452:
11 │ 2,531 2,539 3,539 3,547 4,547 5,059 10,891 12,619 13,619 13,627
21 │ 13,691 13,907 14,419
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 
Found 23 of the smallest primes < 15,000 such that the difference of successive terma are the smallest cubic numbers