Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I want to get the list of k-partition, and the rule are below:

  1. here are k partitions
  2. all elements of partition are in the range of 1 to 30.
  3. the total of element from each partition equals to 30.

For example, if k=5, the partition includes {1,1,1,1,26},{1,1,1,2,25},{1,1,1,3,24}......

Many thanks!!!

share|improve this question
IntegerPartitions[tot, {k}]


IntegerPartitions[30, {5}]

If you need permutations of these, Map that over the results, e.g.

Permutations /@ IntegerPartitions[30, {5}]


Join @@ Permutations /@ IntegerPartitions[30, {5}]

if you need a "flat" list of them.

I note you've asked a few questions about the same kind of thing. Perhaps clarifying what exactly your're trying to do might lead to a generalized answer...

share|improve this answer
Thanks for your answer! What I exactly desire to know is this… But no one answer to me:( – Winnie Lee Mar 1 '14 at 2:39
@WinnieLee: I looked at the question you reference, it is a good example of what I mean. Adding to that question what it is you're trying to accomplish might elicit answers, like "I want to find out how the number of sets of numbers from 1 to k with a total of n changes with k and n" (or whatever it is you are actually trying to do). Few are willing, or have the time, to parse code and try to read minds to figure out intent. When/if readers do answer a question, perhaps also accept one, it rewards effort. – ciao Mar 1 '14 at 2:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.