MathGroup Archive 2004

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

Search the Archive

Re: Partitioning a list into unequal partitions


"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

In[1]:= n = 5; r = Range[n(n+1)/2]

Out[1]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}

In[2]:= Map[Take[r,#+{1,0}]&,Partition[FoldList[Plus,0,Range[n]],2,1]]

Out[2]= {{1},{2,3},{4,5,6},{7,8,9,10},{11,12,13,14,15}}


  • Prev by Date: RE: Re: Is there any productive way to use Mathematica + pdfLaTeX?
  • Next by Date: Re: Partitioning a list into unequal partitions
  • Previous by thread: Re: Partitioning a list into unequal partitions
  • Next by thread: Re: Partitioning a list into unequal partitions