Anonymous user
Proper divisors: Difference between revisions
m
→version 2: added whitespace.
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Optimize, add some verbiage about optimization and concurrency) |
m (→version 2: added whitespace.) |
||
Line 3,642:
<lang rexx>/*REXX program finds proper divisors (and count) of integer ranges; finds the max count.*/
parse arg bot top inc range xtra /*obtain optional arguments from the CL*/
if bot=='' | bot=="," then bot=
if top=='' | top=="," then top=
if inc=='' | inc=="," then inc=
if range=='' | range=="," then range=
w=
numeric digits max(9, w
@.= 'and' /*a literal used to separate #s in list*/
do n=bot to top by inc /*process the first range specified. */
q= Pdivs(n);
if q=='∞' then #=
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors: " q
end /*n*/
Line 3,657:
m=0 /*M ≡ maximum number of Pdivs (so far).*/
do r=1 for range /*process the second range specified. */
q= Pdivs(r);
if #<m then iterate /*Less then max? Then ignore this #. */
@.#= @.# @. r; m=#
end /*r*/ /* [↑] process 2nd range of integers.*/
Line 3,665:
", and it's for: " subword(@.m, 3)
say /* [↓] handle any given extra numbers.*/
do i=1 for words(xtra); n= word(xtra, i)
w= max(w, 1 + length(n) )
numeric digits max(9, 1 + length(n) ) /*have enough digits for // operator.*/
q= Pdivs(n);
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors."
end /*i*/ /* [↑] support extra specified integers*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Pdivs: procedure; parse arg x,b; x= abs(x);
odd= x // 2;
if x//j==0 then do; a=a j; b=x%j b /*if ÷, add both divisors to α & ß. */
end
|