I am writing a small program and I need to calculate integer partitions of a handful of numbers. In my code I just run IntegerPartitions[k,{n}] and then iterate through the results. Since I only use the result through this iteration I was wondering if there is an easy way to get integer partitions one at a time. This way I am hoping to reduce memory usage and if I am lucky also time.

EDIT: Well yes, I should have given an example. So with IntegerPartitions[6,{3}] we get the result {{4,1,1},{3,2,1},{2,2,2}}, I get this and feed it in a loop and treat each one separately. The problem is that I don't need all of them at once, so when the numbers are big, this list becomes unnecessarily big itself. It would be ideal to implement the functionality of the function IntegerPartitions inside my loop and have only one of the partitions each time.

Of course n and k are known from the beginning. My problem is that the result is generated all at once. The length of the list can be well over one million. (By the way, how do you produce the grey box with the command?)
–
tstDec 18 '12 at 23:38

I am not asking whether I can make ItegerPartitions to give one partition at a time, but how can I write my version of it that does that. I tried but it became too messy too quickly for me to handle.
–
tstDec 18 '12 at 23:41

OK, thanks, this is actually what I am doing now.
–
tstDec 18 '12 at 23:52

You can use the 4'th argument like so: IntegerPartitinos[k,{n},All,{i}] to get the i'th one, I doubt you'll see any speed increase but hopefully memory-usage might decrease
–
sschDec 19 '12 at 0:07

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.