Anonymous user
Proper divisors: Difference between revisions
m
Undo revision 272833 by Gerard Schildberger (talk) edited wrong page.
m (→version 2: added support for an ace being high --or-- low in a straight.) |
m (Undo revision 272833 by Gerard Schildberger (talk) edited wrong page.) |
||
Line 3,634:
With the (function) optimization, it's over '''20''' times faster.
<lang rexx>/*REXX program
parse arg
if bot=='' | bot=="," then bot=
if top=='' |
if inc=='' |
if range=='' | range=="," then
w=1+max(length(top), length(bot), length(range)) /*determine the biggest number of these*/
numeric
do n=bot to top by inc /*process the first range specified. */
q=Pdivs(n); #=words(q) /*get proper divs; get number of Pdivs.*/
if q=='∞'
say right(n, max(20, w) ) 'has' center(#, 4) "proper divisors: " q
end /*n*/
say /* [↑] process 1st range of integers.*/
m=0 /*M ≡ maximum number of Pdivs (so far).*/
do r=1 for range /*process the second range specified. */
q=Pdivs(r); #=words(q) /*get proper divs; get number of Pdivs.*/
if #<m then iterate /*Less then max? Then ignore this #. */
@.#=@.# @. r; m=# /*add this Pdiv to max list; set new M.*/
end /*r*/ /* [↑] process 2nd range of integers.*/
say m ' is the highest number of proper divisors in range 1──►'range,
", and it's for: " subword(@.m, 3)
say /* [↓] handle any given extra numbers.*/
do i=1 for words(xtra); n=word(xtra, i) /*obtain an extra number from XTRA list*/
w=max(w, 1 + length(n) ) /*use maximum width for aligned output.*/
numeric digits max(9, 1 + length(n) ) /*have enough digits for // operator.*/
q=Pdivs(n); #=words(q) /*get proper divs; get number of Pdivs.*/
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. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
r=0 /* [↓] ══integer square root══ ___ */
q=1; do while q<=z; q=q*4;
end /*while q>1*/ /* [↑] compute the integer sqrt of X.*/
/* [↓] adjust for a square. ___*/
▲ _= substr(pips, #, 1) + 1 /*obtain the number of the pip in hand.*/
▲ kinds= max(kinds, _) /*convert certain pips to their number.*/
▲ end /*i*/ /* [↑] keep track of N─of─a─kind. */
▲ return 'high-card'</lang>
{{out|output|text= when using the following input: <tt> 0 10 1 20000 166320 1441440 11796480000 </tt>}}
<pre>
|