IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Create all possible combinations of series of letters


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 10:31 am
Reply with quote

Hi All,
Is any way to get all combinations of series of letters using REXX.
I meant that i have letters A,E,I,O,U.I want to create the all possible combinations using this letters.
For this is any inbuilt function or do i have to write the logic for this?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Jul 10, 2009 11:15 am
Reply with quote

It will be all down to you - based on your current description of the problem / request.

Maybe if you explained better and gave some example of what you want
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 11:24 am
Reply with quote

Example
I have the letters A,E,I,O,U. I want to create the all the combination of words using this letters.
Like
AEIOU
AEIUO
AEUIO
AUEIO
UAEIO............ etc

Now are you clear with my requirement?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 10, 2009 12:31 pm
Reply with quote

do you want permutations or combinations?
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 12:38 pm
Reply with quote

i want combinations
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 10, 2009 12:55 pm
Reply with quote

combinations would be:

AAAAA
AAAAE
AAAEE

whereas permutations means each letter can only be used once in the sequence.

so, which is it?
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 1:46 pm
Reply with quote

i want combination a letter can repeat more than once in a word.Is it possible?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 10, 2009 1:54 pm
Reply with quote

Quote:
i want combination a letter can repeat more than once in a word.Is it possible?


sure it is.

what logic have you designed? or do you expect us to design, develop and then deliver the product to you?

develop some pseudo-code and someone can help you with the commands necessary.
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 2:00 pm
Reply with quote

Still i didnt designed any logic.If you give some idea of logic,it will great help for me.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 10, 2009 2:32 pm
Reply with quote

Bipin, you tend to try solving your own problems, so I am not going to rant.

in fact, since it is so easy I am just going to give you the answer.

Code:

/* REXX */
stem1.0 = 5
stem1.1 = 'A'
stem1.2 = 'B'
stem1.3 = 'C'
stem1.4 = 'D'
stem1.5 = 'E'
stem2.0 = 5
stem2.1 = 'A'
stem2.2 = 'B'
stem2.3 = 'C'
stem2.4 = 'D'
stem2.5 = 'E'
stem3.0 = 5
stem3.1 = 'A'
stem3.2 = 'B'
stem3.3 = 'C'
stem3.4 = 'D'
stem3.5 = 'E'
stem4.0 = 5
stem4.1 = 'A'
stem4.2 = 'B'
stem4.3 = 'C'
stem4.4 = 'D'
stem4.5 = 'E'
stem5.0 = 5
stem5.1 = 'A'
stem5.2 = 'B'
stem5.3 = 'C'
stem5.4 = 'D'
stem5.5 = 'E'

outputstem. = ''
outputstem.0 = 1
/*then I would have a complex loop */

do r = 1 to stem1.0
  do s = 1 to stem2.0
     do t = 1 to stem3.0
       do u = 1 to stem4.0
         do v = 1 to stem5.0
            j = outputstem.0
            outputstem.j = stem1.r || stem2.s || stem3.t || stem4.u || stem5.v
            outputstem.0 = outputstem.0 + 1
         end
       end
     end
  end
end
outputstem.0 = outputstem.0 - 1
say outputstem.0
do r = 1 to outputstem.0
   say outputstem.r
end


you will have to figure out how to output the results to a dataset.
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 2:38 pm
Reply with quote

Thanks Dick,I got the logic which you given.This seems give the result which i expected.
Thanks alot
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Jul 10, 2009 2:40 pm
Reply with quote

Code:

/* REXX *** CARTESIAN JOIN OVER 5 STEMS                              */
TRACE R                                                                 
STM0.1 = 'A'                                                           
STM0.2 = 'E'                                                           
STM0.3 = 'I'                                                           
STM0.4 = 'O'                                                           
STM0.5 = 'U'                                                           
STM0.0 = 5                                                             
DO AA = 1 TO STM0.0                                                     
  DO AB = 1 TO STM0.0                                                   
    INTERPRET "STM"AA"."AB "= STM0."AB                                 
  END                                                                   
END                                                                     
DO AA = 1 TO STM0.0                                                     
  DO AB = 1 TO STM0.0                                                   
    DO AC = 1 TO STM0.0                                                 
      DO AD = 1 TO STM0.0                                               
        DO AE = 1 TO STM0.0                                             
          OUTPUT = STM1.AA||STM2.AB||STM3.AC||STM4.AD||STM5.AE
          SAY OUTPUT                                           
        END                                                   
      END                                                     
    END                                                       
  END                                                         
END                                                           
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Jul 10, 2009 2:42 pm
Reply with quote

Damn ..... beaten to it by Dick "the fingers" Brenholtz icon_lol.gif
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 2:48 pm
Reply with quote

Expat you are great..(excuse me if you are not icon_biggrin.gif icon_biggrin.gif )

I didnt get this statement
Code:
INTERPRET "STM"AA"."AB "= STM0."AB       


What is this doing?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 10, 2009 2:50 pm
Reply with quote

expat, I may have been faster, but yours is a much better script.

Besides, my sequence is A B C D E instead of A E I O U

Dick "the fumbler" Brenholtz icon_redface.gif
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 2:54 pm
Reply with quote

Dick and expat,
I think instead of using 5 different stems we can use one stem with 5 different indexes.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 10, 2009 2:58 pm
Reply with quote

Bipin,

enough freebies for today.

you could turn on the trace instruction and watch
or
read the 28 topics have matches for: INTERPRET in the REXX Reference Manuel
or the 9 topics have matches for: INTERPRET in the REXX users guide
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 10, 2009 3:00 pm
Reply with quote

bipinpeter wrote:
Dick and expat,
I think instead of using 5 different stems we can use one stem with 5 different indexes.


well, share your code.
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 3:03 pm
Reply with quote

here is the code

Code:
* REXX */
stem1.0 = 5
stem1.1 = 'A'
stem1.2 = 'B'
stem1.3 = 'C'
stem1.4 = 'D'
stem1.5 = 'E'

outputstem. = ''
outputstem.0 = 1
/*then I would have a complex loop */

do r = 1 to stem1.0
  do s = 1 to stem1.0
     do t = 1 to stem1.0
       do u = 1 to stem1.0
         do v = 1 to stem1.0
            j = outputstem.0
            outputstem.j = stem1.r || stem1.s || stem1.t || stem1.u || stem5.v
            outputstem.0 = outputstem.0 + 1
         end
       end
     end
  end
end
outputstem.0 = outputstem.0 - 1
say outputstem.0
do r = 1 to outputstem.0
   say outputstem.r
end
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Jul 10, 2009 3:03 pm
Reply with quote

bipinpeter wrote:
Expat you are great..(excuse me if you are not icon_biggrin.gif icon_biggrin.gif )
I didnt get this statement
Code:
INTERPRET "STM"AA"."AB "= STM0."AB       

What is this doing?

Aaaaaaaah shucks icon_redface.gif

INTERPRET is a pretty powerful statement in REXX
The parts within the double quotes are literals, and the parts outside can be substituted by the current value of other variables.

For example
when using a value of 3 for AA, and 4 for AB becomes
STM3.4 = STM0.4

It is a great statement, I suggest you try doing that piece using TRACE R or TRACE I to follow it through. It's a great statement to have in the armoury, but it took me a couple of goes to get it right
Code:

TRACE R
DO AA = 1 TO STM0.0                                                     
  DO AB = 1 TO STM0.0                                                   
    INTERPRET "STM"AA"."AB "= STM0."AB                                 
  END                                                                   
END       
TRACE O
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 10, 2009 3:17 pm
Reply with quote

That's greate Bipin.

buuuuuuuuuuuuut, you have a typo:
outputstem.j = stem1.r || stem1.s || stem1.t || stem1.u || stem5.v


sorry, could not resist.
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Fri Jul 10, 2009 3:31 pm
Reply with quote

Yes Dick you are right
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Jul 10, 2009 5:54 pm
Reply with quote

Just for a laugh I tried to get this to work with a variable number of characters icon_lol.gif
Yeah, work is a little slow today

A bit cack-handed ....... but it does work icon_eek.gif
Code:

/* REXX *** CARTESIAN JOIN OVER N STEMS                 
                                                       
"ALTLIB DEACTIVATE APPL(EXEC)"                         
"ALTLIB ACTIVATE   APPL(EXEC) DA('My REXX Library')"           
"FREE FI(INDATA)"                                       
"ALLOC FI(INDATA) DA('My REXX Library(CARTESA8)') SHR"         
"EXECIO * DISKR INDATA ( STEM STM0. FINIS"             
"FREE FI(INDATA)"                                       
                                                       
QUEUE """FREE FI(INDATA)"""                             
QUEUE """ALLOC FI(INDATA) DA('My REXX Library(CARTESA8)') SHR"""
QUEUE """EXECIO * DISKR INDATA ( STEM STM0. FINIS"""   
QUEUE """FREE FI(INDATA)"""                             
QUEUE "DO AA = 1 TO STM0.0"                             
QUEUE "  STM0.AA = STRIP(STM0.AA)"                     
QUEUE "END"                                             
QUEUE "DO AA = 1 TO STM0.0"                     
QUEUE "  DO AB = 1 TO STM0.0"                   
QUEUE '    INTERPRET "STM"AA"."AB "= STM0."AB '
QUEUE "  END"                                   
QUEUE "END"                                     
                                               
"FREE FI(NEXREXX)"                             
"ALLOC FI(NEXREXX) DA('My REXX Library(CARTESA9)') SHR"
                                               
DO AA = 1 TO STM0.0                             
  IF AA = 1 THEN DO                             
    OUT = "/*   TRACE R    */"                 
    QUEUE OUT                                   
  END                                           
  INTERPRET "OUT = 'DO A'"AA"' = 1 TO STM0.0'" 
  QUEUE OUT                                     
END                                             
"EXECIO" QUEUED() "DISKW NEXREXX"               
                                               
DO AA = 1 TO STM0.0                     
  IF AA = 1 THEN DO                     
    OUT = "OUTPT = STM0.A"AA"|| ,"       
    QUEUE OUT                           
  END                                   
  ELSE DO                               
    IF AA = STM0.0 THEN DO               
      OUT = "        STM0.A"AA           
      QUEUE OUT                         
      OUT = "SAY OUTPT"                 
      QUEUE OUT                         
    END                                 
    ELSE DO                             
      OUT = "        STM0.A"AA"|| ,"     
      QUEUE OUT                         
    END                                 
  END                                   
END                                     
                                         
DO AA = 1 TO STM0.0                       
  OUT = "END"                             
  QUEUE OUT                               
END                                       
"EXECIO" QUEUED() "DISKW NEXREXX ( FINIS"
                                         
CALL CARTESA9                             
                                         
EXIT                                     
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2372
Location: Silicon Valley

PostPosted: Fri Jul 10, 2009 9:24 pm
Reply with quote

In Bipinpeter's example:

Code:
outputstem.0 = 1
...
            j = outputstem.0
            outputstem.j = stem1.r || stem1.s || stem1.t || stem1.u || stem5.v
            outputstem.0 = outputstem.0 + 1
....
outputstem.0 = outputstem.0 - 1


I suggest starting with 0 and only incrementing when you have the next value. Then you do not need to subtract:
Code:
j = 0
...
            j = j + 1
            outputstem.j = stem1.r || stem1.s || stem1.t || stem1.u || stem1.v
....
outputstem.0 = j
[/code]
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts COBOL - create and write to output fi... COBOL Programming 0
No new posts Best way to create an automated line ... TSO/ISPF 3
No new posts FD Section to Create FB or Vb File Dy... COBOL Programming 1
No new posts create table with more than 32k recor... DB2 1
No new posts Create table from List CLIST & REXX 8
Search our Forums:

Back to Top