Jump to content

Topswops: Difference between revisions

m
→‎{{header|REXX}}: changed some comments and whitespace.
m (→‎{{header|REXX}}: elided a comment.)
m (→‎{{header|REXX}}: changed some comments and whitespace.)
Line 1,812:
 
do n=1 for things; #=decks(n, n) /*create a (things) number of "decks". */
mx= (n\==1 ) /*handle the case of a one-card deck.*/
do i=1 for #; p=swops(!.i) /*compute the SWOPS for this iteration.*/
if p>mx then mx=p /*This a new maximum? Use a new max. */
Line 1,826:
if ?>y then do; _=@.1; do j=2 for y-1; _=_ @.j; end /*j*/; #=#+1; !.#=_
end
else do; qm=? - 1
if ?==1 then qs=2 /*don't use 1-swops that start with 1 */
else if @.1==? then qs=2 /*skip the 1-swops: 3 x 1 x ···*/
Line 1,834:
end /*k*/
@.?=q; call .decks ? + 1
end /*q*/
end
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
swops: parse arg z; do u=1; parse var z t .; if length(t)==2 then t=x2d(t)
if word(z, t)==1 then return u /*found unity at T. */
do h=10 to things; if pos(h, z)==0 then iterate
z=changestr(h, z, d2x(h) ) /* [↑] any H's in Z ? */
end /*h*/
z=reverse( subword(z, 1, t) ) subword(z, t + 1)
end /*u*/</lang>
Some older REXXes don't have a '''changestr''' bif, so one is included here &nbsp; ───► &nbsp; [[CHANGESTR.REX]].
Cookies help us deliver our services. By using our services, you agree to our use of cookies.