User:Spundun/Math

TRICOUNT
For any new level added we need to calculate the # of new upright triangles and new inverted triangles.

Upright Triangles
For any level $$l$$, The # of new upright triangles is

$$\frac{l}{2}(l+1)$$

So the cumulative upright triangles are

$$\sum_{l=1}^{L}\frac{1}{2}(l^2+l)$$

$$=\frac{1}{2}\sum_{l=1}^{L}l^2+\frac{1}{2}\sum_{l=1}^{L}l$$

$$=\frac{1}{2}(\frac{2L^3+3L^2+L}{6}+\frac{L^2+L}{2})$$

$$=\frac{1}{2}(\frac{2L^3+3L^2+L}{6}+\frac{3L^2+3L}{6})$$

$$=\frac{1}{2} \frac{2L^3+6L^2+4L}{6}$$

$$= \frac{L^3+3L^2+2L}{6}$$

Inverted Triangles
For any level $$l$$, the biggest inverted triangle will have sides $$w_{max} = \lfloor \frac{l}{2} \rfloor$$

For both $$l=2, l=3, w_{max} = 1 : l=4, l=5, w_{max}=2$$ ... and so on.

The # of inverted triangles over the level $$l$$ of side $$w$$ will be

So the total # of inverted triangles introduced by a level $$l$$ will be $$\sum_{w=1}^{w_{\mathrm{max}}}l-2w+1$$

$$=lw_{max}-2(\frac{w_{\max}}{2}(w_{max}+1)) +w_{max}$$

$$=lw_{\max}-w_{max}(w_{max}+1) +w_{max}$$

$$=lw_{\max}-w_{\max}^2$$

$$w_{\max}$$ is a function of $$l$$ so we can write it as $$w_{\max_l}$$

So total accumulated inverted triangles over all the levels is

$$\sum_{l=1}^{L}lw_{\max_l}-w_{\max_l}^2$$

Expressing $$l$$ in terms of $$w_{\max_l}$$

$$l = 2w_{\max_l}$$ if $$l$$ is even

$$l = 2w_{\max_l}+1$$ if $$l$$ is odd

an even and odd pair would have the same $$w_{\max_l}$$

So the summation can be written as

$$\sum_{w=0}^{\lfloor \frac{L-1}{2} \rfloor}w(2w) - w^2 + w(2w+1) - w^2$$ plus (if $$L$$ is even) $$L(\frac{L}{2})-(\frac{L}{2})^2$$

$$=\sum_{w=0}^{\lfloor \frac{L-1}{2} \rfloor}2w^2+w$$ plus (if $$L$$ is even) $$\frac{L^2}{4}$$

$$=2\sum_{w=0}^{\lfloor \frac{L-1}{2} \rfloor}w^2+\sum_{w=0}^{\lfloor \frac{L-1}{2} \rfloor}w$$ plus (if $$L$$ is even) $$\frac{L^2}{4}$$

$$=2\frac{\lfloor \frac{L-1}{2} \rfloor(\lfloor \frac{L-1}{2} \rfloor+1)(2\lfloor \frac{L-1}{2} \rfloor+1)}{6} +\frac{\lfloor \frac{L-1}{2} \rfloor(\lfloor \frac{L-1}{2} \rfloor+1)}{2}$$ plus (if $$L$$ is even) $$\frac{L^2}{4}$$

$$=\frac{(\lfloor \frac{L-1}{2} \rfloor^2+\lfloor \frac{L-1}{2} \rfloor)(2\lfloor \frac{L-1}{2} \rfloor+1)}{3} +\frac{\lfloor \frac{L-1}{2} \rfloor^2+\lfloor \frac{L-1}{2} \rfloor}{2}$$ plus (if $$L$$ is even) $$\frac{L^2}{4}$$

$$=\frac{\lfloor \frac{L-1}{2} \rfloor^2+\lfloor \frac{L-1}{2} \rfloor + 2\lfloor \frac{L-1}{2} \rfloor^3+2\lfloor \frac{L-1}{2} \rfloor^2}{3} + \frac{\lfloor \frac{L-1}{2} \rfloor^2+\lfloor \frac{L-1}{2} \rfloor}{2}$$ plus (if $$L$$ is even) $$\frac{L^2}{4}$$

$$=\frac{2\lfloor \frac{L-1}{2} \rfloor^3+3\lfloor \frac{L-1}{2} \rfloor^2+\lfloor \frac{L-1}{2} \rfloor}{3} + \frac{\lfloor \frac{L-1}{2} \rfloor^2+\lfloor \frac{L-1}{2} \rfloor}{2}$$ plus (if $$L$$ is even) $$\frac{L^2}{4}$$

$$=\frac{4\lfloor \frac{L-1}{2} \rfloor^3+9\lfloor \frac{L-1}{2} \rfloor^2+5\lfloor \frac{L-1}{2} \rfloor}{6} $$ plus (if $$L$$ is even) $$\frac{L^2}{4}$$