Skip to main content
2 of 2
added 127 characters in body
ybeltukov
  • 43.9k
  • 5
  • 109
  • 215

How many triangles are there?

Some time ago I found a puzzle and it stopped my work until I solved it.

One of the possible solutions:

Let us sum upright and upside down triangles whose top lies in the $i$-th row. $$ N=\sum_{i=1}^n N_i^\Delta + N_i^\nabla. $$

For upright triangles we should multiply the number of possible sizes $n-i+1$ by the number of possible horizontal positions $i$ $$ N_i^\Delta = (n-i+1)i. $$ An upside down triangle with size $l$ at $i$-th row have $n-i-l+1$ positions and the size $l$ limited by $\min(i,n-i)$, therefore $$ N_i^\nabla = \sum_{l=1}^{\min(i,n-i)}(n-i-l+1). $$

Finally, we have $$ N=\sum_{i=1}^n\Bigl((n-i+1)i+\sum_{l=1}^{\min(i,n-i)}(n-i-l+1)\Bigr). $$

For $n=28$ rows we get $N=5985$ triangles.

My question is: could you suggest a less trivial solution, which can reveal the power of the different sides of Mathematica? I mean look at this problem from different sides: finding a sequence, image-processing, finding a cycles in a graph and so on.

ybeltukov
  • 43.9k
  • 5
  • 109
  • 215