Anonymous user
Proper divisors: Difference between revisions
m
→version 2: added support for an ace being high --or-- low in a straight.
m (→version 2: added wording to the REXX section header.) |
m (→version 2: added support for an ace being high --or-- low in a straight.) |
||
Line 3,634:
With the (function) optimization, it's over '''20''' times faster.
<lang rexx>/*REXX program
parse arg
numeric digits max(9, w) /*have enough digits for // operator.*/▼
@.= 'and' /*a literal used to separate #s in list*/▼
if q=='∞' then #=q /*adjust number of Pdivisors for zero. */▼
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
kinds= 0;
if mc=='' then mc= 5; n= words(hand); if n\==mc then return 'invalid'
do j=1 for n;
pip= left(_, length(_) - 1); ws= right(_, 1) /*obtain the card's pip; and the suit.*/
if pip==10 then
@._= @._ + 1
#= pos(pip, 123456789TJQK)
if pos(ws, "♥♣♦♠")==0 then return 'invalid suit in card:' _
end▼
if #==0
if @._\==1 then return 'invalid, duplicate card:' _
flush= max(flush, suit.ws)
run= overlay(., run, #) /*convert runs to a series of periods. */
▲
pips= overlay(_, pips, #) /*convert the pip to legitimate number.*/
▲
run= run || left(run, 1) /*An ace can be high ─or─ low. */
pairs= countstr(2, pips) /*count number of pairs (2s in PIPS).*/
straight= pos(....., run || left(run, 1) ) \== 0 /*does the RUN contains a straight? */
if flush==5 & straight then return 'straight-flush'
if kinds==4 then return 'four-of-a-kind'
if kinds==3 & pairs==1 then return 'full-house'
if flush==5 then return 'flush'
if straight then return 'straight'
if kinds==3 then return 'three-of-a-kind'
if kinds==2 & pairs==2 then return 'two-pair'
if kinds==2 then return 'one-pair'
{{out|output|text= when using the following input: <tt> 0 10 1 20000 166320 1441440 11796480000 </tt>}}
<pre>
|