Find the missing permutation: Difference between revisions

→‎{{header|REXX}}: condensed the REXX program to not use a subroutine and other structural changes. -- ~~~~
(→‎{{header|REXX}}: condensed the REXX program to not use a subroutine and other structural changes. -- ~~~~)
Line 1,115:
 
=={{header|REXX}}==
<lang rexx>/*REXX program finds a missing permuation from an internal list. */
<lang rexx>
/*REXX program finds a missing permuation from an internal list. */
 
list='ABCD CABD ACDB DACB BCDA ACBD ADCB CDAB DABC BCAD CADB CDBA',
list='ABCD',
'CBAD ABDC ADBC BDCA DCBA BACD BADC BDAC CBDA DBCA DCAB'
'CABD',
'ACDB',
'DACB',
'BCDA',
'ACBD',
'ADCB',
'CDAB',
'DABC',
'BCAD',
'CADB',
'CDBA',
'CBAD',
'ABDC',
'ADBC',
'BDCA',
'DCBA',
'BACD',
'BADC',
'BDAC',
'CBDA',
'DBCA',
'DCAB'
 
@.=; @abcU='ABCDEFGUIJKLMNOPQRSTUVWXYZ'
@.=''
things=4
bunch=4
do j=1 for things do j=1 for things /*build list of permutation obj. */
@abc='abcdefguijklmnopqrstuvwxyz'
$.j=substr(@abcu,j,1)
@abcu=@abc; upper @abcu
end /*j*/
 
call permset( 1)
do j=1 for things /*build list of permutation obj. */
$.j=substr(@abcu,j,1)
end
 
!='$. @. bunch list things'
call permset(1)
exit
/*─────────────────────────────────────PERMSET subroutine───────────────*/
 
permset:procedure expose (!)$. @. bunch list things; parse arg ?
 
if ?>bunch then do; _=@.1; do m=2 to bunch
permset:procedure expose (!); parse arg ?
_=_||@.m
if ?>bunch then call chkMissing
else do x=1 for things /*construction a new permuation. end /*m*/
if wordpos(_,list)==0 dothen k=1say _ ' is missing from forthe ?-1list.'
if @.k==$.x then iterate xend
else do x=1 for things end /*construction a new permuation. */
do k=1 for ?-1; if @.k==$.x then iterate x; end /*k*/
@.?=$.x
call permset( ?+1)
end /*x*/
return</lang>
'''output'''
 
 
chkMissing: _=@.1
 
do j=2 to bunch
_=_||@.j
end
 
if wordpos(_,list)==0 then say _ 'is missing from the list.'
return
</lang>
Output:
<pre style="height:5ex;overflow:scroll">
DBAC is missing from the list.
</pre>