MathGroup Archive 2000

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

Search the Archive

Re: Partition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22101] Re: [mg22091] Partition
  • From: BobHanlon at aol.com
  • Date: Mon, 14 Feb 2000 02:03:52 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Use the standard add-on package

Needs["DiscreteMath`Combinatorica`"]

For example, for three variables summing to 10

Without regard to order

Select[Partitions[10], Length[#] == 3 &]

{{8, 1, 1}, {7, 2, 1}, {6, 3, 1}, {6, 2, 2}, {5, 4, 1}, 
  {5, 3, 2}, {4, 4, 2}, {4, 3, 3}}

Length[%]

8

Taking order into count

Select[Compositions[10, 3], FreeQ[#, 0] &]

{{1, 1, 8}, {1, 2, 7}, {1, 3, 6}, {1, 4, 5}, {1, 5, 4}, 
  {1, 6, 3}, {1, 7, 2}, {1, 8, 1}, {2, 1, 7}, {2, 2, 6}, 
  {2, 3, 5}, {2, 4, 4}, {2, 5, 3}, {2, 6, 2}, {2, 7, 1}, 
  {3, 1, 6}, {3, 2, 5}, {3, 3, 4}, {3, 4, 3}, {3, 5, 2}, 
  {3, 6, 1}, {4, 1, 5}, {4, 2, 4}, {4, 3, 3}, {4, 4, 2}, 
  {4, 5, 1}, {5, 1, 4}, {5, 2, 3}, {5, 3, 2}, {5, 4, 1}, 
  {6, 1, 3}, {6, 2, 2}, {6, 3, 1}, {7, 1, 2}, {7, 2, 1}, 
  {8, 1, 1}}

Length[%]

36

Bob Hanlon

In a message dated 2/13/2000 2:34:24 AM, kaixiu at students.uiuc.edu writes:

>I am wondering how to do a partition work in Mathematica which is like
>give all the solutions of
>x_1+x_2+x_3+...+x_n=n
>where all x's are positive integers and not necessarily be different to
>each
>other.
>


  • Prev by Date: Re: Sorting
  • Next by Date: Re: string + variable order
  • Previous by thread: Re: Partition
  • Next by thread: Size of axis in printed graphics