How to resolve the algorithm Find the missing permutation step by step in the REXX programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Find the missing permutation step by step in the REXX programming language

Table of Contents

Problem Statement

Listed above are   all-but-one   of the permutations of the symbols   A,   B,   C,   and   D,   except   for one permutation that's   not   listed.

Find that missing permutation.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Find the missing permutation step by step in the REXX programming language

Source code in the rexx programming language

/*REXX pgm finds one or more missing permutations from an internal list & displays them.*/
list= 'ABCD CABD ACDB DACB BCDA ACBD ADCB CDAB DABC BCAD CADB CDBA CBAD ABDC ADBC BDCA',
      "DCBA BACD BADC BDAC CBDA DBCA DCAB"       /*list that is missing one permutation.*/
@.=                                              /* [↓]  needs to be as 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*/                     /* [↑]  build a letter array for speed.*/
call permSet 1                                   /*invoke PERMSET subroutine recursively*/
exit                                             /*stick a fork in it,  we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
permSet: procedure expose $. @. bunch list things; parse arg ? /*calls self recursively.*/
         if ?>bunch  then do;  _=
                                   do m=1  for bunch           /*build a permutation.   */
                                   _= _  ||  @.m               /*add permutation──►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 permutation.   */
                                   do k=1  for ?-1
                                   if @.k==$.x  then iterate x /*was permutation built? */
                                   end  /*k*/
                          @.?= $.x                             /*define as being built. */
                          call permSet  ?+1                    /*call self recursively. */
                          end   /*x*/
         return


  

You may also check:How to resolve the algorithm Find the missing permutation step by step in the 11l programming language
You may also check:How to resolve the algorithm Copy a string step by step in the Frink programming language
You may also check:How to resolve the algorithm Circles of given radius through two points step by step in the Stata programming language
You may also check:How to resolve the algorithm Use another language to call a function step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Arrays step by step in the KonsolScript programming language