View previous topic :: View next topic
|
Author |
Message |
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
do you want permutations or combinations? |
|
Back to top |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
i want combinations |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
i want combination a letter can repeat more than once in a word.Is it possible? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Still i didnt designed any logic.If you give some idea of logic,it will great help for me. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Thanks Dick,I got the logic which you given.This seems give the result which i expected.
Thanks alot |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Damn ..... beaten to it by Dick "the fingers" Brenholtz |
|
Back to top |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Expat you are great..(excuse me if you are not )
I didnt get this statement
Code: |
INTERPRET "STM"AA"."AB "= STM0."AB |
What is this doing? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
Back to top |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Dick and expat,
I think instead of using 5 different stems we can use one stem with 5 different indexes. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
bipinpeter wrote: |
Expat you are great..(excuse me if you are not )
I didnt get this statement
Code: |
INTERPRET "STM"AA"."AB "= STM0."AB |
What is this doing? |
Aaaaaaaah shucks
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Yes Dick you are right |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Just for a laugh I tried to get this to work with a variable number of characters
Yeah, work is a little slow today
A bit cack-handed ....... but it does work
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 |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2593 Location: Silicon Valley
|
|
|
|
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 |
|
|
|