Teaser 2663: Missed the plot
From The Sunday Times, 6th October 2013 [link] [link]
My friend has a triangular vegetable plot, all sides being whole numbers of metres. Coincidentally, the dimensions of the plot are such that its perimeter (in metres) is the same as its area (in square metres). Also, the length of one of the sides is the average of the lengths of the other two sides.
What are the lengths of the sides of the plot?
[teaser2663]
Jim Randell 9:37 am on 7 July 2020 Permalink |
The triangle has sides of integer lengths (a, b, c) such that b = (a + c)/2.
We can use Heron’s Formula [ @wikipedia ] to equate the area of the triangle with the perimeter, which gives us some restrictions on the sides of the triangle.
However, we have encountered “equable” triangles before in Enigma 364, and generated a list of the 5 equable triangles, from which we can easily pick out the one that has one side that is an average of the other two.
I also wrote code to generate k-equable triangles (integer sided triangles where the area is k times the perimeter), and that code can be reused here:
Run: [ @repl.it ]
from enigma import irange, isqrt, divc, divf, printf # find all triangles with integer sides where area = k . perimeter def triangles(k=1): K = 4 * k * k for p in irange(1, isqrt(3 * K)): for q in irange(max(p, divc(K + 1, p)), divf(3 * K, p)): (r, z) = divmod(K * (p + q), p * q - K) if r < q: break if z == 0: yield (p + q, p + r, q + r) # consider 1-equable triangles for (a, b, c) in triangles(1): if b - a == c - b: printf("a={a} b={b} c={c}")Solution: The lengths of the sides of the plot are: 6m, 8m, 10m.
LikeLike
GeoffR 10:54 am on 8 July 2020 Permalink |
for a in range (3, 25): for b in range (a+1, 25): for c in range(b+1, 25): # a < b < c and 2 * b = a + c if 2 * b != a + c: continue # Square of perimeter perim_sq = (a + b + c) ** 2 # Area squared formula is based in Heron's formula area_sq = 1/16 *( 4*a*a*b*b - (a*a + b*b - c*c)**2) if perim_sq == area_sq: print(f"Length of sides are {a}, {b} and {c}m") # Length of sides are 6, 8 and 10mA (5,12,13) triangle has the area equal to the perimeter numerically, but does not have one side as the average of the other two sides.
LikeLike