MathGroup Archive 2001

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

Search the Archive

Re: [Q] Generalized Partitions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29971] Re: [mg29942] [Q] Generalized Partitions
  • From: BobHanlon at aol.com
  • Date: Fri, 20 Jul 2001 03:28:34 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2001/7/19 4:15:11 AM, jkawczak at math.uncc.edu writes:

>do you know of a function in Mathematica that could do the partitioning
>of a number into a fixed number of components out of predefined set,
>i.e. partition number 10 into the elements from the set {1,3,4,5,6,7,9}
>and each partition should have exactly, say, 2 elements.  Of course, I
>have in mind a much bigger problem.
>

Needs["DiscreteMath`Combinatorica`"];

partSum1[s_Integer, n_Integer, l_List] := 
    Select[Partitions[s], Length[#]==n && l == Union[l, #]&];

partSum2[s_Integer, n_Integer, l_List] := 
    Select[KSubsets[l, n], (Plus@@#)==s&];


If you intended to allow for duplication of elements then

partSum1[10, 2, {1, 3, 4, 5, 6, 7, 9}]

{{9, 1}, {7, 3}, {6, 4}, {5, 5}}

partSum1[10, 3, {1, 3, 4, 5, 6, 7, 9}]

{{6, 3, 1}, {5, 4, 1}, {4, 3, 3}}


If duplication is not allowed

partSum2[10, 2, {1, 3, 4, 5, 6, 7, 9}]

{{1, 9}, {3, 7}, {4, 6}}

partSum2[10, 3, {1, 3, 4, 5, 6, 7, 9}]

{{1, 3, 6}, {1, 4, 5}}


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: Order of coefficients in output
  • Next by Date: Re: notation help: f(x) = (sin x)^(1/3)
  • Previous by thread: Re: [Q] Generalized Partitions
  • Next by thread: Re: [Q] Generalized Partitions