Re: Partitioning a list into unequal partitions

*To*: mathgroup at smc.vnet.net*Subject*: [mg47496] Re: [mg47454] Partitioning a list into unequal partitions*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>*Date*: Wed, 14 Apr 2004 07:16:51 -0400 (EDT)*References*: <200404131026.GAA10787@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

*This message was transferred with a trial version of CommuniGate(tm) Pro* On 13 Apr 2004, at 19:26, DIAMOND Mark R. 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) > > I can't see a way, and yet I'm sure there *must* be a one-liner using > Fold. > > Cheers > > Mark R. Diamond > > > Well, it kind of depends on the meaning of "simple" and "non-procedural". For example, what does the follwoing qualify: f[l_List] := (Take[l, #1] & ) /@ Table[{(1/2)*i*(i + 1) + 1, (1/2)*(i + 1)* (i + 2)}, {i, 0, (1/2)* (-3 + Sqrt[1 + 8*Length[l]])}] This will work provided your list is of the right length. For example: l=Range[6*7/2] Out[73]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21} f[l] {{1},{2,3},{4,5,6},{7,8,9,10},{11,12,13,14,15},{16,17,18,19,20,21}} Andrzej Kozlowski Chiba, Japan http://www.mimuw.edu.pl/~akoz/

**References**:**Partitioning a list into unequal partitions***From:*"DIAMOND Mark R." <dot@dot.dot>