Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
add comment

1 Answer 1

IntegerPartitions[tot, {k}]

e.g.

IntegerPartitions[30, {5}]

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

Permutations /@ IntegerPartitions[30, {5}]

or

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 question...:mathematica.stackexchange.com/questions/43123/… But no one answer to me:( –  Winnie Lee Mar 1 at 2:39
1  
@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. –  rasher Mar 1 at 2:46
add comment

Your Answer

 
discard

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.