Teaser 2560: Three trees
From The Sunday Times, 16th October 2011 [link] [link]
Our front garden is circular, with a diameter less than 100 metres. Three trees grow on the perimeter: an ash, a beech and a cherry, each a different whole number of metres from each of the other two. A straight trellis 84 metres long joins the ash to the beech, and a honeysuckle grows at the point on the trellis nearest to the cherry tree. The distance from the cherry to the ash plus the distance from the ash to the honeysuckle equals the distance from the cherry to the beech.
What is the diameter of the garden?
[teaser2560]
Jim Randell 10:26 am on 10 December 2024 Permalink |
We represent the trees by points A, B, C on the perimeter of the circle.
If the sides of the triangle (opposite A, B, C) are a, b, c, then the diameter of the circumcircle d is given by:
where T is the area of the triangle.
In this case we have:
and also:
equating values for h^2 allows us to calculate a (and b) knowing c1 and c2:
This Python program considers possible splits of c into integers c1, c2, and then checks that the resulting a, b values form a viable triangle.
It runs in 66ms. (Internal runtime is 84µs).
from enigma import (decompose, div, sq, rcs, fdiv, printf) # split c into 2 integers c = 84 for (c1, c2) in decompose(c, 2): # calculate a and b, and check (a, b, c) form a viable triangle a = div(sq(c2), 2 * c1) if a is None or not (a < 100): continue b = a - c1 if not (b > 0 and a + b > c): continue # output solution h = rcs(a, -c2) d = fdiv(a * b, h) printf("c1={c1} c2={c2} -> a={a} b={b} c={c} -> h={h} d={d}")Solution: The diameter of the garden is 85 metres.
The 84m trellis (AB) is split into 60m and 24m lengths by the honeysuckle. And the distances AC and BC are 51m and 75m.
And it turns out the height of the triangle is also an integer (h = 45), so we have two Pythagorean triples that share a non-hypotenuse length:
But the next smallest solution (which is eliminated by the d < 100 requirement) does not have an integer height (or diameter):
LikeLike
Frits 12:18 pm on 11 December 2024 Permalink |
Trellis length 84 is cleverly chosen.
For D=100 we only have to investigate c1 values 22, 24 and 26.
The following program shows solutions with a integer diameter less than 1000 meters.
from math import ceil D = 1000 # with a diameter less than D metres # a = c2**2 / (2 * c1) < D, (c - c1)**2 < 2 * D * c1, c1**2 - 2 * (D + c1) * c1 + c**2 < 0 # (c1 - (D + c))**2 < (D + c)**2 - c**2 # c1 > D + c - ((D + c)**2 - c**2)**.5 # c1 > 20.29 # a + b > 84 or c2**2 / c1 - c1 > 84 or (84 - c1)**2 / c1 - c1 > 84 # (84 - c1)**2 > c1**2 + 84 * c1 or 252 * c1 < 84**2 # c1 < 28 prt = 0 hdr = " (c1, c2) c2^2 2*c1 ( a, b) a + b h d " sols = [] for c in range(3, D): if prt: print(hdr) min_c1 = int(D + c - ((D + c)**2 - c**2)**.5) + 1 # c2 must be even if a is an integer #for c1 in range(1 + (c % 2 == 0), ceil(c / 3), 2): for c1 in range(min_c1 + ((c - min_c1) % 2), ceil(c / 3), 2): c2 = c - c1 a = round(c2**2 / (2 * c1), 2) b = round(a - c1, 2) h = round((b**2 - c1**2)**.5 if b >= c1 else -1, 2) d = round(a * b / h if h > 0 else -1, 2) OK = (' OK' if a + b > c and int(a) == a and int(d) == d and all (x < D for x in [a, b, d]) else '') txt = (f"({c1:>3}, {c2:>3}) " + f"{c2**2:>6} " + f"{2 * c1:>3} ({a:>9}, {b:>9}) " + f"{round(a + b, 2):>9} " + f"{h:>10} " + f"{d:>10} " + f"{round(D + c - ((D + c)**2 - c**2)**.5, 2) :>8} < c1 < " + f"{round(c / 3, 2):>6} " + f"{OK}") if prt: print(txt) if OK: sols.append(txt) if h == -1: break print("solutions with a integer diameter:\n") print(hdr) for s in sols: print(s) ''' solutions with a integer diameter: (c1, c2) c2^2 2*c1 ( a, b) a + b h d ( 1, 16) 256 2 ( 128.0, 127.0) 255.0 127.0 128.0 0.14 < c1 < 5.67 OK ( 1, 18) 324 2 ( 162.0, 161.0) 323.0 161.0 162.0 0.18 < c1 < 6.33 OK ( 1, 20) 400 2 ( 200.0, 199.0) 399.0 199.0 200.0 0.22 < c1 < 7.0 OK ( 1, 22) 484 2 ( 242.0, 241.0) 483.0 241.0 242.0 0.26 < c1 < 7.67 OK ( 1, 24) 576 2 ( 288.0, 287.0) 575.0 287.0 288.0 0.3 < c1 < 8.33 OK ( 1, 26) 676 2 ( 338.0, 337.0) 675.0 337.0 338.0 0.35 < c1 < 9.0 OK ( 1, 28) 784 2 ( 392.0, 391.0) 783.0 391.0 392.0 0.41 < c1 < 9.67 OK ( 1, 30) 900 2 ( 450.0, 449.0) 899.0 449.0 450.0 0.47 < c1 < 10.33 OK ( 1, 32) 1024 2 ( 512.0, 511.0) 1023.0 511.0 512.0 0.53 < c1 < 11.0 OK ( 1, 34) 1156 2 ( 578.0, 577.0) 1155.0 577.0 578.0 0.59 < c1 < 11.67 OK ( 1, 36) 1296 2 ( 648.0, 647.0) 1295.0 647.0 648.0 0.66 < c1 < 12.33 OK ( 1, 38) 1444 2 ( 722.0, 721.0) 1443.0 721.0 722.0 0.73 < c1 < 13.0 OK ( 1, 40) 1600 2 ( 800.0, 799.0) 1599.0 799.0 800.0 0.81 < c1 < 13.67 OK ( 1, 42) 1764 2 ( 882.0, 881.0) 1763.0 881.0 882.0 0.89 < c1 < 14.33 OK ( 2, 42) 1764 4 ( 441.0, 439.0) 880.0 439.0 441.0 0.93 < c1 < 14.67 OK ( 1, 44) 1936 2 ( 968.0, 967.0) 1935.0 967.0 968.0 0.97 < c1 < 15.0 OK ( 2, 44) 1936 4 ( 484.0, 482.0) 966.0 482.0 484.0 1.01 < c1 < 15.33 OK ( 2, 46) 2116 4 ( 529.0, 527.0) 1056.0 527.0 529.0 1.1 < c1 < 16.0 OK ( 2, 48) 2304 4 ( 576.0, 574.0) 1150.0 574.0 576.0 1.19 < c1 < 16.67 OK ( 2, 50) 2500 4 ( 625.0, 623.0) 1248.0 623.0 625.0 1.29 < c1 < 17.33 OK ( 2, 52) 2704 4 ( 676.0, 674.0) 1350.0 674.0 676.0 1.38 < c1 < 18.0 OK ( 2, 54) 2916 4 ( 729.0, 727.0) 1456.0 727.0 729.0 1.49 < c1 < 18.67 OK ( 2, 56) 3136 4 ( 784.0, 782.0) 1566.0 782.0 784.0 1.59 < c1 < 19.33 OK ( 2, 58) 3364 4 ( 841.0, 839.0) 1680.0 839.0 841.0 1.7 < c1 < 20.0 OK ( 2, 60) 3600 4 ( 900.0, 898.0) 1798.0 898.0 900.0 1.81 < c1 < 20.67 OK ( 2, 62) 3844 4 ( 961.0, 959.0) 1920.0 959.0 961.0 1.93 < c1 < 21.33 OK ( 24, 60) 3600 48 ( 75.0, 51.0) 126.0 45.0 85.0 3.26 < c1 < 28.0 OK ( 36, 120) 14400 72 ( 200.0, 164.0) 364.0 160.0 205.0 10.57 < c1 < 52.0 OK ( 48, 120) 14400 96 ( 150.0, 102.0) 252.0 90.0 170.0 12.15 < c1 < 56.0 OK ( 46, 138) 19044 92 ( 207.0, 161.0) 368.0 154.29 216.0 14.38 < c1 < 61.33 OK ( 32, 192) 36864 64 ( 576.0, 544.0) 1120.0 543.06 577.0 20.67 < c1 < 74.67 OK ( 42, 210) 44100 84 ( 525.0, 483.0) 1008.0 481.17 527.0 25.62 < c1 < 84.0 OK ( 72, 180) 32400 144 ( 225.0, 153.0) 378.0 135.0 255.0 25.62 < c1 < 84.0 OK ( 81, 180) 32400 162 ( 200.0, 119.0) 319.0 87.18 273.0 27.31 < c1 < 87.0 OK ( 36, 228) 51984 72 ( 722.0, 686.0) 1408.0 685.05 723.0 27.88 < c1 < 88.0 OK ( 72, 240) 57600 144 ( 400.0, 328.0) 728.0 320.0 410.0 37.64 < c1 < 104.0 OK ( 96, 240) 57600 192 ( 300.0, 204.0) 504.0 180.0 340.0 42.94 < c1 < 112.0 OK ( 92, 276) 76176 184 ( 414.0, 322.0) 736.0 308.58 432.0 50.43 < c1 < 122.67 OK (120, 300) 90000 240 ( 375.0, 255.0) 630.0 225.0 425.0 63.53 < c1 < 140.0 OK (108, 360) 129600 216 ( 600.0, 492.0) 1092.0 480.0 615.0 76.6 < c1 < 156.0 OK (144, 360) 129600 288 ( 450.0, 306.0) 756.0 270.0 510.0 86.96 < c1 < 168.0 OK (162, 360) 129600 324 ( 400.0, 238.0) 638.0 174.36 546.0 92.31 < c1 < 174.0 OK (168, 420) 176400 336 ( 525.0, 357.0) 882.0 315.0 595.0 112.87 < c1 < 196.0 OK (144, 480) 230400 288 ( 800.0, 656.0) 1456.0 640.0 820.0 124.67 < c1 < 208.0 OK (192, 480) 230400 384 ( 600.0, 408.0) 1008.0 360.0 680.0 140.99 < c1 < 224.0 OK (198, 528) 278784 396 ( 704.0, 506.0) 1210.0 465.65 765.0 160.11 < c1 < 242.0 OK (216, 540) 291600 432 ( 675.0, 459.0) 1134.0 405.0 765.0 171.07 < c1 < 252.0 OK (240, 600) 360000 480 ( 750.0, 510.0) 1260.0 450.0 850.0 202.93 < c1 < 280.0 OK (264, 660) 435600 528 ( 825.0, 561.0) 1386.0 495.0 935.0 236.4 < c1 < 308.0 OK '''LikeLike
Jim Randell 9:30 am on 12 December 2024 Permalink |
@Frits: Your code gives solutions that are close to a whole number of metres, rather than exactly a whole number of metres.
For example, the first configuration you give:
Here is some code that looks for pairs of Pythagorean triples that share a non-hypotenuse side to find solutions where h and d are (exact) integers:
from enigma import (defaultdict, pythagorean_triples, subsets, div, arg, printf) D = arg(100, 0, int) printf("[d < {D}]") # collect pythagorean triples by non-hypotenuse sides d = defaultdict(list) for (x, y, z) in pythagorean_triples(D - 1): d[x].append((y, z)) d[y].append((x, z)) # look for pairs of triangles for (h, ts) in d.items(): if len(ts) < 2: continue for ((c1, b), (c2, a)) in subsets(sorted(ts), size=2): c = c1 + c2 if not (a == b + c1 and c < D): continue d = div(a * b, h) if d is None: continue printf("a={a} b={b} c={c} -> c1={c1} c2={c2} h={h} d={d}")Note that if h is an integer, then d will be rational (but not necessarily an integer).
LikeLike
Frits 11:26 am on 12 December 2024 Permalink |
@Jim, you are right.
I get the same output as your program if I only do rounding during printing (which I should have done).
LikeLike
Brian Gladman 6:56 pm on 13 December 2024 Permalink |
Finding all solutions:
# (a - b).(a + b + 2.c) = c^2 = p.q with p < q # # a - b = p ) a = (p + q) / 2 - c # a + b + 2.c = q ) b = a - p from enigma import divisor_pairs from fractions import Fraction as RF c = 84 print(' a b d^2') for p, q in divisor_pairs(c * c): t, r = divmod(p + q, 2) a = t - c b = a - p if not r and a > 0 and 2 * b > a: d2 = RF(a * b * b, b + b - a) print(f"{a:4} {b:4} {d2:16}")LikeLike
GeoffR 10:59 am on 14 December 2024 Permalink |
LikeLike