I am working on recursive formulas and I managed to solve the fib formula and got it to
F(0) = 0
F(1) = 1
F(N) = F(N - 1) + F(N - 2)
Now I stumbled on another problem as you can see in the image that's depicting the problem. I need to find a formula but I find it challenging since it's recursive.
I came up with some thoughts:
Let's call the figure P
This is the series I came up with:
P: 1 2 3 4 5
Number of blocks: 0 1 7 22 50
The amount of blocks in the base: 0 1 6 15 22
You can probably see a pattern here. P is determined by adding together the amounts of blocks in each base in the previous figure.
For instance figure 4, has 22 stone blocks in total. We can do that by adding up 15 + 6 + 1 + 0 = 22
You can also see that the width increases by 1 and the length increases by 2 for each P.
The problem I have here is implementing this pattern as a function, just like I did with the Fib series. I appreciate some help.
This is how I've started:
F(1) = 0
F(2) = 1

We want a recurrence relation that relates $F(P+1)$ and $F(P),$ were $P$ is the term number according to your table above.
This is the key observation. Thus, \begin{align}F(P+1)&=F(P)+\text{width $\times$ length of the added rectangle}\\&=F(P)+P\times\text{the $P$th term of the arithmetic sequence with first term $1$ and common difference $2$}\\&=F(P)+P \times \big(1+ (P-1)2\big)\\&=F(P)+2P^2-P.\end{align}
Supplement to the above answer
Recap: the above recurrence system is $$F(1)=0,\\F(P+1)=F(P)+2P^2-P\quad (P\in\mathbb N).$$
It describes a sequence with a constant “jerk” (third common difference)—in this case, $4$—so it has a cubic closed-form expression.
So, to derive it, plug $P=1,2,3$ into $$F(P)=aP^3+bP^2+cP+d$$ and solve simultaneously:$$\left. \begin{array}{l} 0&=&a+b+c+d\\ 1&=&8a+4b+2c+d\\ 7&=&27a+9b+3c+d\\ 22&=&64a+16b+4c+d \end{array} \right\} \iff a = \frac23 , b = -\frac32 , c = \frac56 , d = 0.$$ Thus, $$F(P)=\frac23P^3-\frac32P^2+\frac56P.$$
Alternatively, its closed form can be derived using telescoping cancellation: \begin{align}F(P+1)-F(P)&=2P^2-P\\&\vdots\\&\vdots \\F(P+1)-F(1)&=2(1^2+2^2+\ldots+P^2)-(1+2+\ldots+P)\\F(P+1)-0&=2\left(\frac{P(P+1)(2P+1)}6\right)-\left(\frac{P(P+1)}2\right)\\F(P)&=2\left(\frac{(P-1)P(2(P-1)+1)}6\right)-\left(\frac{(P-1)P}2\right)\\&=\frac23P^3-\frac32P^2+\frac56P.\end{align}