Find the missing permutation: Difference between revisions

m
Line 873:
 
missing = all - given # ["DBAC"]</lang>
 
=={{header|REXX}}==
<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',
'CBAD',
'ABDC',
'ADBC',
'BDCA',
'DCBA',
'BACD',
'BADC',
'BDAC',
'CBDA',
'DBCA',
'DCAB'
 
@.=''
things=4
bunch=4
@abc='abcdefguijklmnopqrstuvwxyz'
@abcu=@abc; upper @abcu
 
do j=1 for things /*build list of permutation obj. */
$.j=substr(@abcu,j,1)
end
 
!='$. @. bunch list things'
call permset(1)
exit
 
 
permset:procedure expose (!); parse arg ?
if ?>bunch then call chkMissing
else do x=1 for things /*construction a new permuation. */
do k=1 for ?-1
if @.k==$.x then iterate x
end
@.?=$.x
call permset(?+1)
end
return
 
 
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>
 
=={{header|Scala}}==