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!!!

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...

  • $\begingroup$ Thanks for your answer! What I exactly desire to know is this question...:mathematica.stackexchange.com/questions/43123/… But no one answer to me:( $\endgroup$ – Winnie Lee Mar 1 '14 at 2:39
  • 1
    $\begingroup$ @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. $\endgroup$ – ciao Mar 1 '14 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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