MathGroup Archive 2004

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

Search the Archive

Re: Partitioning a list into unequal partitions


In article <c5gfdp$an0$1 at smc.vnet.net>, "DIAMOND Mark R." <dot at dot.dot> 
wrote:

> Could someone please show me a simple (non-procedural) way of partitioning a
> list into 1,2,3 ... n disjoint sublists, where the length of the list is
> guaranteed to be correct (i.e. n*(n+1)/2)

If I understand your question (a definite example would have helped), 
for a list, lst, how about

  Sort[ReplaceList[lst, {___, a__, ___} -> {a}]]

This gives a list of length n*(n+1)/2 if lst is of length n.

> I can't see a way, and yet I'm sure there *must* be a one-liner using Fold.

I don't see how Fold will do what you want. Distribute might work. For 
example, 

 PowerSet[t_List]:=Sort[Distribute[{{},{#}} & /@ t,List,List,List,Join]]

gives a sorted list of all subsets of a list. 

Cheers,
Paul

-- 
Paul Abbott                                   Phone: +61 8 9380 2734
School of Physics, M013                         Fax: +61 8 9380 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: Returning rules ...
  • Next by Date: Re: Regarding a 3D plot in mathematica
  • Previous by thread: Re: Partitioning a list into unequal partitions
  • Next by thread: RE: Partitioning a list into unequal partitions