How would I go about calculating the total number of possible triangles where the perimeter is given, and all sides are integers?
Exempli gratia:
- $a + b + c = 15$
- $d + e + f = 16$
- $x + y + z = 100$
How would I go about calculating the total number of possible triangles where the perimeter is given, and all sides are integers?
Exempli gratia:
An efficient approach can be found with little algebraic manipulation :
Since $a + c > b$ or, $p – b > b$ or, $b < p/2$. Thus iterating $b$ from $1$ to $p/2$, calculating $a$ and storing only the whole number $a$ would give all solutions for a given $p$. There are no right triangles are possible for odd $p$.
This is given in A005044. The generating function is $\frac{x^3}{(1-x^2)(1-x^3)(1-x^4)}$ Some other formulas and references are given as well
It rather depends on whether you regard 7,5,4 as the same triangle as 5,7,4 (edges in a different order), and whether you allow the triangles 8,8,0 (with a zero edge) or 8,5,3 (with a zero area). Let's suppose not in what follows.
So start with the longest side: it cannot be longer than or equal to half the perimeter, but it must be at least a third of the perimeter. So that gives you a limited set of values. Now consider the middle sized side: it must be at least half the difference between the perimeter and the longest side, but cannot be longer than the longest side. Together these will tell you the shortest side. So just add up the number of different shortest sides for each possible longest side.
For example with a perimeter of 15, the longest side must be 5, 6 or 7. If it is 5 then the middle side can be 5; if it is 6 then the middle side can be 5 or 6; if it is 7 then the middle side can be 4, 5, 6 or 7. Adding those up gives 1+2+4 = 7.
Similar results can be found for other small perimeters. It is also possible to derive a general formula which has the curious property that $a(2n-3) = a(2n)$, or in other words, starting with a triangle with an odd perimeter, we can find a related triangle with a perimeter 3 more just by adding 1 to each side.
Let ${\cal S}_p$ be the set of ordered triples $(a,b,c) \in \mathbb{N}^3$ such that $c \ge b \ge a \ge 1$, $a+b+c=p$, and $a+b > c$ (the triangle inequality). For instance, ${\cal S}_3 = \{ (1,1,1) \}$ and ${\cal S}_4 = \{ \}$. Each triple in ${\cal S}_{p-2}$ gives rise to a triple in ${\cal S}_{p}$ under the transformation $(a,b,c)\rightarrow(a,b+1,c+1)$, and all triples in ${\cal S}_{p}$ are produced by this transformation except for those of the form $(a,a,c)$. These latter triples can be counted directly: there is one for each value of $a$ for which $3a \le p < 4a$, and so there are exactly $I_p = \lfloor{p/3}\rfloor - \lceil{(p+1)/4}\rceil + 1$ of them. So we have the recurrence $S_p = S_{p-2} + I_p$ for the values of $S_p = |{\cal S}_p|$, with initial conditions $S_0=S_1=0$. The addend has period $12$, and takes on values $ I_{12k+(0,1,2,...,11)} = k + (0,0,0,1,0,0,1,1,0,1,1,1). $ We then have $S_{12(k+1)} = S_{12k} + 6k + 3$ and $S_{12(k+1)+1} = S_{12k+1} + 6k + 5$, leading to quadratic solutions $S_{12k} = 3k^2$ and $S_{12k+1} = 3k^2 + 2k$. The full set of solutions is $ \begin{eqnarray} S_{12k} &=& 3k^2 \\ S_{12k+1} &=& 3k^2 + 2k \\ S_{12k+2} &=& 3k^2 + k \\ S_{12k+3} &=& 3k^2 + 3k + 1\\ S_{12k+4} &=& 3k^2 + 2k \\ S_{12k+5} &=& 3k^2 + 4k + 1 \\ S_{12k+6} &=& 3k^2 + 3k + 1 \\ S_{12k+7} &=& 3k^2 + 5k + 2 \\ S_{12k+8} &=& 3k^2 + 4k + 1 \\ S_{12k+9} &=& 3k^2 + 6k + 3 \\ S_{12k+10} &=& 3k^2 + 5k + 2 \\ S_{12k+11} &=& 3k^2 + 7k + 4. \end{eqnarray} $ Note that, as noted elsewhere, for all odd $p$ we have $S_{p} = S_{p+3}$.
No of possible triangles $n$ having perimeter $p= p^2/48$ if $p$ is even.