Cubic special primes: Difference between revisions

Content added Content deleted
(Added Algol W)
m (→‎{{header|REXX}}: simplified code, added a foot sep, changed whitespace and comments.)
Line 400: Line 400:
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. */
@cbp= 'the smallest primes < ' commas(hi) " such that the" ,
title= 'the smallest primes < ' commas(hi) " such that the" ,
'difference of successive terma are the smallest cubic numbers'
'difference of successive terma are the smallest cubic numbers'
if cols>0 then say ' index │'center(@cbp , 1 + cols*(w+1) )
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) ) /*display the title.*/
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " sep.*/
cbp= 0; idx= 1 /*initialize number of cbp and index.*/
found= 0; idx= 1 /*initialize number of cbp and index.*/
op= 1
op= 1
$= /*a list of nice primes (so far). */
$= /*a list of cubic primes (so far). */
do j=0 by 0
do j=0 by 0
do k=1 until !.np; np= op + k**3 /*find the next square + oldPrime.*/
do k=1 until !.np
if np>= hi then leave j /*Is newPrime too big? Then quit.*/
np= op + k**3 /*find the next cube plus the oldPrime.*/
end /*k*/
if np>= hi then leave j /*Is newPrime too big? Then quit. */
cbp= cbp + 1 /*bump the number of cbp's. */
end /*k*/
found= found + 1 /*bump number of primes of this type. */
op= np /*assign the newPrime to the oldPrime*/
op= np /*assign the newPrime to the oldPrime*/
if cols==0 then iterate /*Build the list (to be shown later)? */
if cols<0 then iterate /*Build the list (to be shown later)? */
c= commas(np) /*maybe add commas to the number. */
c= commas(np) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) ) /*add a nice prime ──► list, allow big#*/
$= $ right(c, max(w, length(c) ) ) /*add a cubic prime──►list, allow big#.*/
if cbp//cols\==0 then iterate /*have we populated a line of output? */
if found//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 422: Line 423:


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), '─') /*display foot sep. */
say
say
say 'Found ' commas(cbp) " of " @cbp
say 'Found ' commas(found) " of " title
exit 0 /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 450: Line 452:
11 │ 2,531 2,539 3,539 3,547 4,547 5,059 10,891 12,619 13,619 13,627
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
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
Found 23 of the smallest primes < 15,000 such that the difference of successive terma are the smallest cubic numbers