Find the missing permutation: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments.
No edit summary
m (→‎{{header|REXX}}: added/changed whitespace and comments.)
Line 1,591:
 
=={{header|REXX}}==
<lang rexx>/*REXX program finds (a)one or more missing permutation(s)permutations from an internal list.*/
list = 'ABCD CABD ACDB DACB BCDA ACBD ADCB CDAB DABC BCAD CADB CDBA',
'CBAD ABDC ADBC BDCA DCBA BACD BADC BDAC CBDA DBCA DCAB'
@.= /* [↓] needs to be THINGSas long. as THINGS.*/
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*an uppercase (Latin/Roman) alphabet. */
things = 4 /*#number of unique letters to be used. */
bunch = 4 /*#number letters to be used at a time. */
do j=1 for things /* [↓] only get a portion of alphabet.*/
$.j=substr(@abcU,j,1) /*extract just one letter from alphabet*/
end /*j*/ /* [↑] constructbuild a letter array for speed.*/
call permsetpermSet 1 /*invoke PERMSET sub. (recursively). */
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────PERMSET subroutine──────────────────*/
permsetpermSet: procedure expose $. @. bunch list things; parse arg ?
if ?>bunch then do
_=; do m=1 for bunch /*build a permutation. */
_=_ || @.m /*add perm ──► listpermutation──►list*/
end /*m*/
/* [↓] is in the list? */
if wordpos(_,list)==0 then say _ ' is missing from the list.'
end
else do x=1 for things /*build a new permpermutation. */
do k=1 for ?-1
 
if @.k==$.x then doiterate x k=1 /*was forpermutation built?-1*/
if @.k==$.x then iterate x end /*been built?k*/
@.?=$.x end /*kdefine as being built.*/
@.?=$.x call permSet ?+1 /*define ascall builtsubr. recursively*/
call permset ?+1 /*call recursively.*/
end /*x*/
return</lang>