Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: [Q] Generalized Partitions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29990] Re: [mg29942] [Q] Generalized Partitions
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Fri, 20 Jul 2001 03:28:56 -0400 (EDT)
  • References: <200107190757.DAA02234@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Perhaps this will help, and surely it can be improved, but it works. I first
select all partitions of length 2 and then I check if all elements belong to
the set {1,3,4,5,6,7,9}.

In[1]:=
<< DiscreteMath`Combinatorica`
In[2]:=
?Partitions
"Partitions[n] gives all partitions of integer n in reverse lexicographic \
order."
In[3]:=
parts = Partitions[10]
Out[3]=
{{10}, {9, 1}, {8, 2}, {8, 1, 1}, {7, 3}, {7, 2, 1}, {7, 1, 1, 1}, {6, 4},
{6,
     3, 1}, {6, 2, 2}, {6, 2, 1, 1}, {6, 1, 1, 1, 1}, {5, 5}, {5, 4, 1}, {5,
    3, 2}, {5, 3, 1, 1}, {5, 2, 2, 1}, {5, 2, 1, 1, 1}, {5, 1, 1, 1, 1,
    1}, {4, 4, 2}, {4, 4, 1, 1}, {4, 3, 3}, {4, 3, 2, 1}, {4, 3, 1, 1, 1},
{4,
     2, 2, 2}, {4, 2, 2, 1, 1}, {4, 2, 1, 1, 1, 1}, {4, 1, 1, 1, 1, 1, 1},
{3,
     3, 3, 1}, {3, 3, 2, 2}, {3, 3, 2, 1, 1}, {3, 3, 1, 1, 1, 1}, {3, 2, 2,
2,
     1}, {3, 2, 2, 1, 1, 1}, {3, 2, 1, 1, 1, 1, 1}, {3, 1, 1, 1, 1, 1, 1,
    1}, {2, 2, 2, 2, 2}, {2, 2, 2, 2, 1, 1}, {2, 2, 2, 1, 1, 1, 1}, {2, 2,
1,
    1, 1, 1, 1, 1}, {2, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1,
    1}}
In[4]:=
cset = {1, 3, 4, 5, 6, 7, 9};
In[5]:=
lengthtwo = Select[parts, Length[#] == 2 &]
Out[5]=
{{9, 1}, {8, 2}, {7, 3}, {6, 4}, {5, 5}}
In[6]:=
Extract[lengthtwo, Position[Complement[#, cset] & /@ lengthtwo, {}]]
Out[6]=
{{9, 1}, {7, 3}, {6, 4}, {5, 5}}

Tomas Garza
Mexico City

----- Original Message -----
From: "Janusz Kawczak" <jkawczak at math.uncc.edu>
To: mathgroup at smc.vnet.net
Subject: [mg29990] [mg29942] [Q] Generalized Partitions


> Dear Mathematica users:
>
> 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.
>
> Thank you in advance for your help.
> Janusz Kawczak.
>



  • Prev by Date: Re: password problem
  • Next by Date: Re: Mathematica generating gifs for avi problem
  • Previous by thread: [Q] Generalized Partitions
  • Next by thread: Re: [Q] Generalized Partitions