Topswops: Difference between revisions

18 bytes removed ,  6 years ago
m
→‎{{header|REXX}}: optimized the SWOPS function.
(→‎{{header|REXX}}: elided the need to undo the hex transformation, optimized the functions (about 20% faster).)
m (→‎{{header|REXX}}: optimized the SWOPS function.)
Line 1,766:
<br>and is optimized somewhat to take advantage by eliminating one-swop "decks".
<lang rexx>/*REXX program generates N decks of numbered cards and finds the maximum "swops". */
parse arg things .; if things=='' then things=10; thingsX= things>9
 
do n=1 for things; #=decks(n, n) /*create a (things) number of "decks". */
Line 1,795:
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
swops: parse arg z; do u=1; parse var z t .; if \datatypelength(t,'W')==2 then t=x2d(t)
if word(z, t)==1 then return u /*found unity at T. */
if thingsX then do h=10 to things; /*handle things >if pos(h, z)==0 then 9.*/iterate
z=changestr(h, z, d2x(h) ) /* [↑] any H's in if pos(h, z)==0 Z then? iterate*/
z=changestr(h, z, d2x(h) ) /* [↑] hexify decimal H */
end /*h*/
z=reverse(subword(z, 1, t)) subword(z, t+1)
end /*u*/</lang>