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.


if there is an easy way to get integer partitions one at a timeCan you give a small example of what this means? – Nasser Dec 18 '12 at 22:55IntegerPartitions[n, {k}]has to know thenandkvalues at that time it is called in order to generate the whole list. There is no way to tell it: please do not generate the whole list just right now and wait until I tell you when I really need something, and only then give me one number at a time I ask you to. I really think you are trying to solve a wrong problem here. list are immutable in Mathematica. How big a list we are talking about here? – Nasser Dec 18 '12 at 23:13