I need to iterate over all K-tuples of nonnegative Ints that sum to N.
Eg if K is 3 and N==3,
(0,0,3)
(0,1,2)
(0,2,1)
(0,3,0)
(1,0,2)
(1,1,1)
(1,2,0)
(2,0,1)
(2,1,0)
(3,0,0)
Ordering does not matter, just full traversal. I need this to be allocation free though.
At the moment, I am not even sure of the algorithm that I would use, so any hints on anything between that and “package X does this” would be helpful.