generate a sequence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting generate a sequence
# 1  
Old 04-15-2011
generate a sequence

how can i generate following sequence
for a given input 1,2,3,4,5

Code:
 
 1->2
 2->3 
3->4 
4->5 

1->2,3
 1,2->3 
2->3,4 
2,3->4 
3->4,5 
3,4->5  

1->2,3,4 
1,2->3,4 
1,2,3->4  

2->3,4,5 
2,3->4,5 
2,3,4->5  

1->2,3,4,5 
1,2->3,4,5 
1,2,3->4,5 
1,2,3,4->5

how can i make a use of shell script over here ?

Last edited by vaibhavkorde; 04-15-2011 at 10:01 AM..
# 2  
Old 04-15-2011
Yes, trivial looping and arithmetic. Is this homework or ?
# 3  
Old 04-15-2011
not homework exactly
it was challenge to me
# 4  
Old 04-15-2011
Well, the first or critial number is generated in the outer loop, and the lines are generated inside using either arithmetic or another loop.
Code:
 
a=0 
while (( ++a < 6 ))
do
 b=$(( a + 1 ))
 echo "$a->$b"
done

# 5  
Old 04-15-2011
python script:
PHP Code:

#!/usr/bin/python

mtn=[]
l=[]
def printSeq(n):
    global 
l
    l 
range(1,n+1)
    
length len(l)
    global 
mtn
    mtn 
= [str(x)+"->"+str(x+1) for x in l if x<l[-1]]
    for 
x in mtn:
        print 
x

    
for x in range(2length):
        print 
"" # empty line
        
for e in range(length):
            if 
e+xlength:
                
generateOtherSeq(l[e:x+e+1])
    
def generateOtherSeq(myl):
    for 
i in range(len(myl)):
        
ll = list(myl)
        if 
i+len(myl):
            
ll[i] = mtn[l.index(myl[i])]
            
ll.remove(ll[i+1])
            print 
",".join([str(x) for x in ll])
         

printSeq(5
you can change the last line "5" to any number you like. for example "7" will give you this output:
Code:
kent$ python pyseq.py
1->2
2->3
3->4
4->5
5->6
6->7

1->2,3
1,2->3
2->3,4
2,3->4
3->4,5
3,4->5
4->5,6
4,5->6
5->6,7
5,6->7

1->2,3,4
1,2->3,4
1,2,3->4
2->3,4,5
2,3->4,5
2,3,4->5
3->4,5,6
3,4->5,6
3,4,5->6
4->5,6,7
4,5->6,7
4,5,6->7

1->2,3,4,5
1,2->3,4,5
1,2,3->4,5
1,2,3,4->5
2->3,4,5,6
2,3->4,5,6
2,3,4->5,6
2,3,4,5->6
3->4,5,6,7
3,4->5,6,7
3,4,5->6,7
3,4,5,6->7

1->2,3,4,5,6
1,2->3,4,5,6
1,2,3->4,5,6
1,2,3,4->5,6
1,2,3,4,5->6
2->3,4,5,6,7
2,3->4,5,6,7
2,3,4->5,6,7
2,3,4,5->6,7
2,3,4,5,6->7

1->2,3,4,5,6,7
1,2->3,4,5,6,7
1,2,3->4,5,6,7
1,2,3,4->5,6,7
1,2,3,4,5->6,7
1,2,3,4,5,6->7


Last edited by sk1418; 04-15-2011 at 12:34 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

Mcookie, pkg -l to generate random sequence

I am setting this thread to this bsd forum, though it may fit into bash. But as using bsd and the terminal, I would like to generate a random sequence of alphanumerical digits, such as I use to do so on linux by typing just mcookiethis one gives me a pretty random password, but it does not on bsd... (0 Replies)
Discussion started by: 1in10
0 Replies

2. Shell Programming and Scripting

Sequence extraction

i want to extract specific region of interest from big file. i have only start position, end position and seq id, see my query is: I have file1 is this >GL3482.1 GAACTTGAGATCCGGGGA GCAGTGGATCTCCACCAG CGGCCAGAACTGGTGCAC CTCCAGGCCAGCCTCGTC CTGCGTGTC >GL3550.1... (14 Replies)
Discussion started by: harpreetmanku04
14 Replies

3. Shell Programming and Scripting

Script to generate sequence of numbers

I need awk script to generate part number sequencing based on data in multiple columns like below Input File --------- Col A|Col B|Col C| 1|a|x| 2|b|y| |c|z| | |m| | |n| And out put should be like 1ax 1ay 1az 1am 1an 1bx 1by (6 Replies)
Discussion started by: aramacha
6 Replies

4. Red Hat

Rm -rf * sequence

If I run rm -rf * command under one parent directory. /data > rm -rf * Is there anyway to know which files will be deleted first ? Start using code tags please, ty. (2 Replies)
Discussion started by: sameermohite
2 Replies

5. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

6. Shell Programming and Scripting

Check Sequence

* Expiry DATE: * Address1: Address2: Address3: Address4: Address5: * PO_ref_number: aadad HolderId_1: HolderId_2: HolderId_3: HolderId_4: * adad: 00000 ada: 00000 adad: RANDOM adad: RANDOM ****************************** (4 Replies)
Discussion started by: arunshankar.c
4 Replies

7. Shell Programming and Scripting

ls all files in sequence. How to?

Hi, all: Newbie questions: For example, if I have 6 files, respectively named as: How to "ls" all files in sequence of two ways? 1) The first way is according to the sequence of the natural number. Say, the same sequence as shown as they are given. 2) The second way is default... (2 Replies)
Discussion started by: jiapei100
2 Replies

8. Shell Programming and Scripting

To grep in sequence

Hi, I have a log file containg records in sequence <CRMSUB:MSIN=2200380,BSNBC=TELEPHON-7553&TS21-7716553&TS22-7716553,NDC=70,MSCAT=ORDINSUB,SUBRES=ONAOFPLM,ACCSUB=BSS,NUMTYP=SINGLE; <ENTROPRSERV:MSIN=226380,OPRSERV=OCSI-PPSMOC-ACT-DACT&TCSI-PPSMTC-ACT-DACT&UCSI-USSD;... (17 Replies)
Discussion started by: helplineinc
17 Replies

9. UNIX for Dummies Questions & Answers

Generate a Sequence like in Oracle

#!/usr/bin/ksh ValUniqueNo=0 export ValUniqueNo FnGenerateUniqueNo() { (( ValUniqueNo = $ValUniqueNo + 1 )) echo $ValUniqueNo export ValUniqueNo=$ValUniqueNo } echo k1=`FnGenerateUniqueNo` echo k2=`FnGenerateUniqueNo` kindly consider the above script. it is required that when... (1 Reply)
Discussion started by: keshav_rk
1 Replies

10. Shell Programming and Scripting

Escape sequence

Hi, I have got an application through which an user will submit an address like "c:\tuser\abc". This application calls a script and passes the address to the scripts positional parameter say $1. So $1 should contain "c:\tuser\abc", but when $1 is echoed the "\t" and "\a" are interpreted to... (4 Replies)
Discussion started by: puspendu
4 Replies
Login or Register to Ask a Question