Almost Equilateral Triangles (94)
In Problem 94, we're tasked to find “almost equilateral” triangles with side lengths either
Equilateral triangle height and area
Let's collect the equations for the equilateral triangle from school. Let's say that our triangle has two sides with
The area of such a triangle is
Integer equilateral triangle with integer area
Right as the first sentence, they give this theorem:
It is easily proved that no equilateral triangle exists with integral length sides and integral area.
In math, “easily” doesn't necessarily mean that it is easy for the reader, just that it doesn't require more advanced math than we already have. And it turns out that it is indeed not involved.
We can just set
This can be simplified by pulling out
Because
The “almost equilateral triangles”
We now look at the case where
We need to find integer areas. Let us pull our the fractions out of the radicand such that we don't need to consider them there. This gives us the simpler expression
In order to have an integer area
Let us call the radicand
From here we do some manipulations, multiply by 3 and complete the square. We end up with
We introduce
This type of equation has occurred multiple times in these problems and it is the Diophantine equation that has it's own library page. In this case we have
Solutions of the Diophantine equation
As written in the library page, we can generate solutions
if
Then we also need to check that
The perimeter of such a triangle is
As the solutions are generated in such an efficient way with the recursion relation, this takes 494 ns with my Rust implementation.