Re: Partitioning lists
- To: mathgroup at smc.vnet.net
- Subject: [mg20527] Re: [mg20439] Partitioning lists
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Sat, 30 Oct 1999 00:13:49 -0400
- Sender: owner-wri-mathgroup at wolfram.com
In mathematica 4 (only) you can indeed do what you want using Partition:
In[58]:=
Array[Partition[{1, 2, 3, 4, 5, 6}, 5, 5, {#, #}, {}] &, {5}]
Out[58]= {{{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}}}
However, it does not seem to me to be obviously more efficient than your
way, but I have not tried running any tests.
--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
> From: "DIAMOND Mark" <noname at noname.com>
To: mathgroup at smc.vnet.net
> Organization: The University of Western Australia
> Date: Tue, 26 Oct 1999 00:33:17 -0400
> To: mathgroup at smc.vnet.net
> Subject: [mg20527] [mg20439] Partitioning lists
>
> I would like a function f to split a list as follows
>
> a={1,2,3,4,5,6}
> f[a] =
> {
> {{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}}
> }
>
> I can do this as
>
> Table[{Take[a, i], Drop[a, i]}, {i, 1, Length[a] - 1}]
>
> but it *looks* as though it is very inefficient. Is it?
> It also looks as though there should be a way of using Partition simply to
> chop a list between positions i and i+1, but
> I cannot see how to do it. Any suggestions?
>
>
> mark diamond
> no spam email: markd at psy dot uwa dot edu dot au
>
>
>
>
>
>