Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
srajanbose
Warnings : 1

New User

Joined: 11 Oct 2004
Posts: 69
Location: chennai

 Posted: Tue Dec 29, 2009 12:38 pm    Post subject: how to get different combination of words from a string REXX Hi, How to get different combination of words from a string using rexx. For example if i give the input as 'COW' i need the output as COW CWO OWC ...

expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8685
Location: Back in jolly old England

 Posted: Tue Dec 29, 2009 12:58 pm    Post subject: The idea of the interview questions forum is that YOU give your answer or suggestion before other forum members step in with replies. We await your response.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10478
Location: italy

Posted: Tue Dec 29, 2009 12:59 pm    Post subject: Reply to: how to get different combination of words from a s

looks more like a math issue, so for this time i' ll post the answer and the code
the scripts prints the permutations in Lexicographical order
the TS should do a bit of research on FACTORADICALS

 Code: #!/opt/ooRexx/bin/rexx numeric digits 27 z    = time("E") src = "abcdefghijklmnopqrstuvwxyz" --- src = "CWO" parse arg n ord if   n > 26 then ,    exit l = length(fact(n)) low = 0 max = fact(n) - 1 if   ord \= "" then ,    if   ord > max then ,       exit    else do       low = ord - 1       max = ord - 1       l   = ""    end     do   m = low to max    k = FRADICALS(m, n)    r = 0    do   i = 1 to k    --   call charout , f.i"x"k-i"! +"       r = r + fact(k-i)*f.i    end    -- say       if   r \= m then do       say "oh shit!"       exit    end    ans = ""    tmp = left(src,n)    do   i = 1 to k       j = f.i + 1       ans = ans || substr(tmp,j,1)       tmp = delstr(tmp,j,1)    end    if l = "" then ,       say m+1 ans    else ,       say right(m+1,l) ans end say "Ended Elaps("time("E")") " exit FRADICALS:procedure expose F.    parse arg M, N    do   I =  1 to N       F.I = 0    end    do   J = 2 while ( M \= 0 )       I = N - J + 1       F.I = M // J       M   = M % J    end    return N exit -1 FACT:procedure    parse arg N    if   N = 0 then ,       return 1    F = 1    do   I = 1 to N       F *= I    end    return F exit -1

the script takes two parameters
the first one is mandatory ans the number of <things>
the second one if entered will print the Nth lexical permutation in Lexicographical order

<scriptname> 3 will yeld
 Code: 1 abc 2 acb 3 bac 4 bca 5 cab 6 cba

scriptname> 3 2 will yeld
 Code: 2 acb

edited to add the correct NUMERIC DIGITS for large numbers

the Lexicographical order in the permutation jargon is the order relative to the original tokens configuration
for the example posted the lLexicographical order generation

 Code: 1 CWO 2 COW 3 WCO 4 WOC 5 OCW 6 OWC
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8685
Location: Back in jolly old England

 Posted: Tue Dec 29, 2009 1:03 pm    Post subject: Enrico, methinks that your code gives cartesian joins on all characters used, so one result would be AAA, but unfortunately there is only one character A in the input. I know this because I thought along exactly the same lines as you did and almost posted my cartesian logic.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10478
Location: italy

 Posted: Tue Dec 29, 2009 1:24 pm    Post subject: Reply to: how to get different combination of words from a s HI Expat! just corrected an posted the right code PS. I had just messed up the script names and had some time ago saved as permutations what really were combinations PS2. reread the thread, the TS asked for combinations, so after all the first script was right I enjoyed more researching and writing the second one anyway
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8685
Location: Back in jolly old England

 Posted: Tue Dec 29, 2009 1:58 pm    Post subject: Hi Enrico, and wishing you a happy and prosperous new year, I must admit after a quick reread, it could have been interpretted anyway one wanted as the OP did not bother to give the full list of output options. So nothing much has improved over the last year then, we still have the same quality of ambiguous / unclear postings.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Rexx code to find greater then symobl... Bharath Vikraman CLIST & REXX 8 Tue May 29, 2018 9:40 am Trap the jcl error message or maxcc i... ankita agarwal CLIST & REXX 5 Fri May 18, 2018 2:08 pm Rexx command to open an another text ... Bharath Vikraman PC Guides & IT News 7 Sat May 12, 2018 4:34 pm GDG gen check using REXX raghuraman123 CLIST & REXX 6 Wed Apr 18, 2018 9:18 pm Find & Replace string in CA-SORT mrgnndhmk CA Products 1 Fri Mar 30, 2018 12:58 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us