I'm having trouble coming up with a closed formula for $n$ from the sequence of numbers generated by this function:
The following mystery function $M : N \times N \rightarrow N $ is defined by: $$ M(m,n) = \begin{cases} m & n < 2m +1 \\ M(m+1, n-2m-1) &n \ge 2m + 1 \end{cases} $$
If that looks confusing here's an algorithm representing the logic:
int M(int m, int n)
{
if (n < 2*m + 1)
return m;
else
M(m + 1, n - 2*m - 1);
}
Here's what I have to do:
Evaluate $M(0,n)$ for $n \in \{0,...,10\}$.
- $n = 0$ : $M(0,0) = 0$
- $n = 1$ : $M(0,1) = 2$
- ...
- I evaluated each $n$ from $0$ to $10$ on paper, and the sequence I got is: $0,1,1,1,2,2,2,2,2,3,3$ I verified this output by running my algorithm in C.
Provide a closed formula for $M(0,n)$
- This is where I'm lost. I know what a closed formula is. It's a formula to find the value of $M(0,n)$ with $n$ in the formula... I ran my program again, but this time from n = 0 to 100, and see a pattern of 0, three 1's, five 2's, seven 3's, nine 4's... and so on... But I don't see how to tie this to n. I think I've been up too late. Any help/insight is appreciated!