Here is my code:
let rec sum n =
if n <= 0 then 0
else if n / 2 * 2 = n then 3 * n + 50 * (sum n-2)
else n + 10 * (sum n-1);;
The math problem is simply as following:
sn =
0 if n = 0
50*sn-2 + 3*n, if n > 0 and n is even
10*sn-1 + n , if n > 0 and n is odd
When I test sum 5, it popped out "stack overflow" error as following:
Stack overflow during evaluation (looping recursion?).
Could anyone help me out?