I have am interesting recursion problem for you. I am interested in an SML solution but feel free to drop a recursive C++ version.
Let's say we have the sum s and I want to generate all the possibilities in which I can write this sum in as the sum of n terms. Let's take an example:
s=4 and n=3 then I want to generate a list that looks like this:
[[0,0,4],[0,1,3],[0,2,2],[0,3,1],[0,4,0],[1,0,3],[1,1,2],[1,2,1],[1,3,0],[2,0,2],
[2,1,1],[2,2,0],[3,0,1],[3,1,0],[4,0,0]]
basically s is the sum and n the number of terms I can use to compute the sum.