[Math] How many Distinct triangle can be made from stick of length N

combinatoricsgeometry

You are given a stick of length N. You want to break it in three pieces such that it can form a triangle. How many distinct triangles can you make? Two triangles are equal if all the side lengths are same when sorted in ascending order of length. So (1, 3, 2) is same to (3, 1, 2) because their side lengths are same if we sort them, which is (1, 2, 3). But (1, 3, 4) is not same with (1, 2, 3). Suppose the lengths of three pieces are X, Y, Z (X ≤ Y ≤ Z) respectively. Following constraints should be maintained:

X, Y, Z > 0.
X, Y, Z is an integer.
X + Y >= Z
X + Y + Z = N

For example if N = 14, then there are 7 triangles: (1, 6, 7), (2, 5, 7), (2, 6, 6), (3, 4, 7), (3, 5, 6), (4, 4, 6), (4, 5, 5).

Best Answer

As noted by Barry Cipra, the number of nondegenerate triangles is given in OEIS A005044. Allowing degenerate ones (due to the restriction $X+Y \ge Z$ permitting equality) adds $\lfloor \frac n4 \rfloor$ when $n$ is even and makes no change when $n$ is odd. This is because to have $X+Y=Z$ with $X \le Y \le Z$ we must have $Z$ even, then we count the values for $X$ as from $1$ to $\lfloor \frac Z2 \rfloor$ I didn't find the resulting sequence in OEIS.