Re: Partitioning a list into unequal partitions
- To: mathgroup at smc.vnet.net
- Subject: [mg47501] Re: Partitioning a list into unequal partitions
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Wed, 14 Apr 2004 07:17:08 -0400 (EDT)
- Organization: The University of Western Australia
- References: <c5gfdp$an0$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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