Wilson primes of order n: Difference between revisions
Content added Content deleted
m (split a long sentence.) |
m (→{{header|REXX}}: changed comments, simplified some code.) |
||
Line 257: | Line 257: | ||
parse value bignum 'E0' with ex 'E' ex . /*obtain possible exponent of factorial*/ |
parse value bignum 'E0' with ex 'E' ex . /*obtain possible exponent of factorial*/ |
||
numeric digits (max(9, ex+2) ) /*calculate max # of dec. digits needed*/ |
numeric digits (max(9, ex+2) ) /*calculate max # of dec. digits needed*/ |
||
call facts hip /* |
call facts hip /*go & calculate a number of factorials*/ |
||
title= ' Wilson primes P of order ' oLO " ──► " oHI', where P < ' commas(hip) |
title= ' Wilson primes P of order ' oLO " ──► " oHI', where P < ' commas(hip) |
||
w= length(title) + 1 /*width of columns of possible numbers.*/ |
w= length(title) + 1 /*width of columns of possible numbers.*/ |
||
say ' order │'center(title, w ) |
say ' order │'center(title, w ) |
||
say '───────┼'center("" , w, '─') |
say '───────┼'center("" , w, '─') |
||
do n=oLO to oHI; nf= !(n-1) /*precalculate a factorial product. */ |
|||
z= -1**n /* " " plus or minus (+1│-1).*/ |
|||
if n==1 then lim= 103 /*limit to known primes for 1st order. */ |
|||
else lim= # /* " " all " " orders ≥ 2.*/ |
|||
$= /*$: a line (output) of Wilson primes.*/ |
|||
do j=1 for lim; p= @.j /*search through some generated primes.*/ |
|||
if (nf*!(p-n)-z)//sq.j\==0 then iterate /*expression ~ q.j ? No, then skip it.*/ /* ◄■■■■■■■ the filter.*/ |
|||
$= $ ' ' commas(p) /*add a commatized prime ──► $ list.*/ |
|||
⚫ | |||
$= $ ' ' commas(p) /*add a commatized prime ──► $ list.*/ |
|||
⚫ | |||
if $=='' then $= ' (none found within the range specified)' |
|||
say center(n, 7)'│' substr($, 2) /*display what Wilson primes we found. */ |
|||
end /*n*/ |
|||
say '───────┴'center("" , w, '─') |
say '───────┴'center("" , w, '─') |
||
exit 0 /*stick a fork in it, we're all done. */ |
exit 0 /*stick a fork in it, we're all done. */ |