Re: Partitioning a list into unequal partitions

• To: mathgroup at smc.vnet.net
• Subject: [mg47492] Re: Partitioning a list into unequal partitions
• From: drbob at bigfoot.com (Bobby R. Treat)
• Date: Wed, 14 Apr 2004 07:16:45 -0400 (EDT)
• References: <c5gfdp\$an0\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```There are many ways, but here's my favorite:

triangleRule = z : {x___List,
y_List} /; Length[y] > Length@z :> {x, Take[y,
Length@z], Drop[y, Length@z]};
triangularPartition[x_List] := {x} //. triangleRule

Here's a test, for lengths from 1 to 20. Note that I leave the extras
in a list at the end when the length isn't "correct".

Composition[triangularPartition, Range] /@ Range@20 // ColumnForm

(output suppressed)

Bobby

"DIAMOND Mark R." <dot at dot.dot> wrote in message news:<c5gfdp\$an0\$1 at smc.vnet.net>...
> 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

```

• Prev by Date: RE: Format Style
• Next by Date: Re: InLine Formatting
• Previous by thread: Re: Partitioning a list into unequal partitions
• Next by thread: Re: Partitioning a list into unequal partitions