MathGroup Archive 2004

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

Search the Archive

Re: Partitioning a list into unequal partitions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47491] Re: Partitioning a list into unequal partitions
  • From: koopman at sfu.ca (Ray Koopman)
  • Date: Wed, 14 Apr 2004 07:16:44 -0400 (EDT)
  • References: <c5gfdp$an0$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"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