5

Suppose one has exactly $n \geqslant 3$ rods, which have lengths $1, 2, \dotsc, n$.

How many non-degenerate triangles can be formed using these rods?

(Clarification: You must use precisely 3 rods in each triangle. Concatenation of rods along a side is not allowed.)

Attempt: By looking at small cases, we can see that

  • $\#\triangle(3) = 0$ as the only "triangle" is the degenerate {1,2,3}
  • $\#\triangle(4) = 1$ via {2,3,4}
  • $\#\triangle(5) = 3$ adding {2,4,5} {3,4,5}
  • $\#\triangle(6) = 7$ adding {2,5,6} {3,4,6} {3,5,6} {4,5,6}

With little data, I'd like to think that $$\#\triangle(n) = (n-3)^2 - (n-3) + 1 = n^2-7n+13$$ for $n>3$ and $0$ otherwise. But I can't quite see how.

D.J.
  • 304

1 Answers1

4

The relevant thing here is the triangle inequality. If you have $0<a<b<c\le n$ then you need $a+b>c$ for a non-degenerate triangle.

Finding the sequence in OEIS

I did a quick and dirty experiement to compute more elements of this sequence:

$$0,1,3,7,13,22,34,50,70,95,125,161,203,252,308,372,444,525,615,715,\dots$$

Looking this up in OEIS, I found it to be A173196 which comes with a closed formula:

$$A_{173196}(n) = \frac{4n^3+6n^2-4n-3+3\cdot(-1)^n}{48}$$

But their counting starts at $1$ where you start at $3$, so you have

$$A(n) = A_{173196}(n-2) = \frac{4n^3-18n^2+20n-3+3\cdot(-1)^n}{48}$$

The OEIS entry also has this comment:

$a(n+1)$ is the number of integer-sided scalene triangles with largest side $\le n$. [Alexander Evnin, Oct 12 2010]

I must confess that I'm somewhat confused as to why this claims an offset of $1$ as opposed to $2$ like I did above. Could this be a mistake in OEIS?

Comparing this with your guess

For $n=7$ this still agrees with your formula, but for $n=8$ I get $22$ but you get $21$. The $22$ triangles in this case are are

$$ \{2,3,4\},\{2,4,5\},\{2,5,6\},\{2,6,7\},\{2,7,8\},\{3,4,5\},\{3,4,6\},\{3,5,6\},\\ \{3,5,7\},\{3,6,7\},\{3,6,8\},\{3,7,8\},\{4,5,6\},\{4,5,7\},\{4,5,8\},\{4,6,7\},\\ \{4,6,8\},\{4,7,8\},\{5,6,7\},\{5,6,8\},\{5,7,8\},\{6,7,8\}$$

Finding a formula on our own

Looking back to the conditions stated in my first paragraph, you can see that you have a lower bound (namely $b+1$) and two upper bounds (namely $n$ and $a+b-1$) for $c$. So you want

$$\sum_{a=1}^{n-2}\sum_{b=a+1}^{n-1}\max(0,\min(n,a+b-1)-(b+1)+1)$$

Obtaining a closed form

So let's try to get rid of those $\min$ and $\max$ and reformulate this to

$$ \begin{array}{rccl} &\sum_{a=1}^{\lfloor n/2\rfloor}&\sum_{b=a+1}^{n-a+1}&(a+b-1)-(b+1)+1 \\+ &\sum_{a=3}^{\lfloor n/2\rfloor}&\sum_{b=n-a+2}^{n-1}&n-(b+1)+1 \\+ &\sum_{a=\lfloor n/2\rfloor+1}^{n-2}&\sum_{b=a+1}^{n-1}&n-(b+1)+1 \end{array} $$

In the first row you have $b\le n-a+1$ therefore $a+b-1\le n$ therefore $\min(n,a+b-1)=a+b-1$. The bounds of the inner sum here are ordered, since

$$(n-a+1)-(a+1)=n-2a\ge n-2\lfloor n/2\rfloor\ge 0$$

In the second row you have $a+b-1>n$ and therefore $\min(n,a+b-1)=n$. Likewise in the third row, where you have $a\ge\lfloor n/2\rfloor+1$ and $b\ge a+1\ge\lfloor n/2\rfloor+1$ so $a+b-1\ge2\lfloor n/2\rfloor+2>n$. The bounds of the inner sum in the third row are obviously ordered, for the second row you might want to check $(n-1)-(n-a+2)=a-3\ge 0$ which is exactly the reason why we have $a=3$ as the start here: for smaller $a$ the inner sum is already completely dealt with in the first row.

Using a computer algebra system to compute the inner sums, I obtain

\begin{align*}A(n)& =\phantom+\sum_{a=1}^{\lfloor n/2\rfloor}(-2a^2 + (a - 1)n + 3a - 1)\\& \phantom=+\sum_{a=3}^{\lfloor n/2\rfloor}\tfrac12(a^2 - 3a + 2)\\& \phantom=+\sum_{a=\lfloor n/2\rfloor+1}^{n-2}\tfrac12(a^2 - (2a + 1)n + n^2 + a) \end{align*}

Writing $k=\lfloor n/2\rfloor$ this becomes

$$A(n)=\frac{-4k^3 + 6k^2n - 3kn^2 + n^3 - 3k^2 + 3kn - 3n^2 + k + 2n}{6}$$

If $n=2k$ is even this can be simplified to

$$A(n=2k)=\frac{2n^3 - 9n^2 + 10n}{24}$$

while for $n=2k+1$ odd this becomes

$$A(n=2k+1)=\frac{2n^3 - 9n^2 + 10n - 3}{24}$$

These two forms can be combined suing the usual $(-1)^n$ trick to distinguish even and odd terms, leading to the equation I stated in the beginning. As an alternative, you could also write this as

$$A(n)=\left\lfloor\frac{2n^3 - 9n^2 + 10n}{24}\right\rfloor$$

and let the floor operation take care of subtracting that three from the numerator if needed.

MvG
  • 42,596
  • This is absolutely remarkable @MvG! I'm disappointed it's not a cleaner solution and feel slightly bad for assigning this to my Geometry students as an exercise. That said, they did discover a nice recursive property: $#\triangle_{\text{degen}}(n) = \left\lfloor\left(\frac{n-1}{2}\right)^2\right\rfloor$, and $#\triangle(n) = #\triangle(n-1) + #\triangle_{\text{degen}}(n)$. – D.J. Dec 05 '14 at 17:54
  • The Prog section of that OEIS link gives the same formula as you derved .. cool.. – mtk Sep 05 '16 at 19:49