Re: List manipulation
- To: mathgroup at smc.vnet.net
 - Subject: [mg7422] Re: [mg7390] List manipulation
 - From: penny at suu.edu (Des Penny)
 - Date: Sat, 31 May 1997 15:07:37 -0400 (EDT)
 - Sender: owner-wri-mathgroup at wolfram.com
 
>Hello,
>
>        I have a list X={1,2,3,4,5,6,7,8}. How do I get a list of the
>folllowing kind:
>
>        S={{1,2,3,4}, {1,2,3,5}, {1,2,3,6}, .....}.
>
>S will have 8-choose-2 = 70 elements. Each element of S should have length
>4.
>
>        Is there any function which does such list making? Something of
>the form
>
>        ?????[list, n]
>
>        Thanks in advance.
>
>
>        V. Nandagopal
>        School of Mathematics
>        Tata Institute of Fundamental Research
>        Colaba, Bombay 400 005, India
>
>        e-mail: nandgopa at math.tifr.res.in
Hi:
This is more general that what you specifically asked for.  The arguments
to the function are:
x= Supplied list
n= Integer defining the number of fixed elements of x at the beginning of
each sublist of the result.
==============================
Clear[f]
f[x_List,n_Integer]:=
Module[{first, rest},
first=Take[x,n];
rest=Drop[x,n];
Map[Join[first,#]&,Map[List,rest]]
]
==============================
Thus for your particular problem:
In:
x={1,2,3,4,5,6,7,8}
f[x,3]
Out:
{{1,2,3,4},{1,2,3,5},{1,2,3,6},{1,2,3,7},{1,2,3,8}}
If we only want 2 fixed elements of x in each sublist we have:
In:
f[{a,c,d,t,a,r},2]
Out:
{{a,c,d},{a,c,t},{a,c,a},{a,c,r}}
Hope this helps.
Cheers,
Des Penny
-------------------------------
Des Penny
Physical Science Dept.
Southern Utah University
Cedar City, UT 84720
VOICE: (Office): (801) 586-7708
       (Home)  : (801) 586-2286
FAX:    (801) 865-8051
e-mail: penny at suu.edu
-------------------------------