Hello, I wrote an algorithm which is finding the number of combinations for a sum number(n in code) and q is the max number. For example : part 7 3 = 8 because we can do :

3+3+1

3+2+2

3+2+1+1

3+1+1+1+1

2+2+2+1

2+2+1+1+1

2+1+1+1+1+1

1+1+1+1+1+1+1

My recursion idea is : part n q = part n q-1 + part n-q q

Here is my code :

let rec part n q =

if n=q then 1+part n q-1

else if q=0||n<0 then 0

else if n=0 || q=1 then 1

else (part (n) (q-1))+(part (n-q) (q))

;;

But I have the error : Stack overflow during evaluation (looping recursion?).

Can you explain me whats going wrong ?

I found the mistake, in line 2 : (q-1) instead of q-1