I\'m writing a function to find triangle numbers and the natural way to write it is recursively:
function triangle (x) if x == 0 then return 0 end retu
Please don't recurse this. Either use the x*(x+1)/2 formula or simply iterate the values and memoize as you go.
int[] memo = new int[n+1]; int sum = 0; for(int i = 0; i <= n; ++i) { sum+=i; memo[i] = sum; } return memo[n];