MathGroup Archive 1996

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: List help needed

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5091] Re: List help needed
  • From: "Seth J. Chandler" <SChandler at uh.edu>
  • Date: Wed, 30 Oct 1996 22:03:39 -0500
  • Organization: University of Houston
  • Sender: owner-wri-mathgroup at wolfram.com

Here's one way of doing it:

Needs["DiscreteMath`Combinatorica`"]

p[\[CapitalNu]_,n_]:=
 
Flatten[Map[Permutations,Select[Partitions[\[CapitalNu]],Length[#]==n&]],1]


cutup[x_List,pieces_]:=
  Map[Take[x,#]&,Map[{1,0}+#&,Partition[FoldList[Plus,0,pieces],2,1]]]

answer[x_List,n_]:=Map[cutup[x,#]&,p[Length[x],n]]

John Rowney wrote:
> 
> Hi,
> 
> I need a little help with lists.  What I would like to do is the
> following:
> 
> From a list of length N, construct all possible lists of length n<N from
> N by combining adjacent elements of the original list into sub lists.
> This might become clearer with an example.
> 
> Given {a,b,c,d,e} of length 5, ALL possible length 4 lists subject to
> the conditions above are:
> 
> {{a,b},c,d,e}, {a,{b,c},d,e}, {a,b,{c,d},e} and {a,b,c,{d,e}}
> 
> two of the possible length 3 lists are
> 
> {a,{b,c,d},e} and {{a,b},c,{d,e}}
> 
> I hope you get the picture.
> 
> In the "real" problem, N would be around 20 and n would be around 10.
> 
> Thanks in advance
> 
> John
> jrowney at arco.com


  • Prev by Date: Windows WAV File Bug & Compiled File Routines
  • Next by Date: PDE-Solving in Mathematica
  • Previous by thread: Re: List help needed
  • Next by thread: ANN: Leibniz 1.1 graphical interface for Mathematica