Teaser 2782: Spiders
From The Sunday Times, 17th January 2016 [link] [link]
Spiders Beth and Sam wake up in the bottom corner of a cuboidal barn (all of whose sides are whole numbers of metres). They want to reach the opposite bottom corner without actually walking across the floor. Beth decides to walk on one of five possible shortest routes, two of them being around the edge of the floor and the other three being over the walls and ceiling. Sam decides instead to spin a web directly to the point on the ceiling diagonally opposite the starting point and then to drop down into the corner. The total length of his journey is within five centimetres of a whole number of metres.
How high is the barn?
[teaser2782]
Jim Randell 10:04 am on 1 April 2021 Permalink |
Suppose the cuboid barn has dimensions width = x, length = y, height = z (all of which are positive integer values).
The spiders wish to traverse from one corner of the floor to the diagonally opposite corner, but without crossing the floor.
Beth walks along one of the 5 shortest routes (which presumably means that there are 5 shortest routes that have the same distance travelled).
Two of these routes (p1, p2) are along the edges of the floor:
To see the other routes we can “unfold” the barn (imagine it is a cardboard box), and the shortest paths will appear as straight lines.
We get a route that crosses the front, ceiling and left wall (p3):
And routes that cross the right wall, ceiling, back wall (p4), and right wall, ceiling, left wall (p5).
So the following expressions all give the square of the minimal path length:
So, given values for x and y, we can calculate z, and then look for diagonals of the cube (= hypot(x, y, z)) that are within 5cm of a whole number of metres, to give Sam’s path.
This Python program runs in 47ms.
Run: [ @replit ]
from enigma import (irange, inf, quadratic, hypot, first, arg, printf) # generate solutions def solve(verbose=1): # consider increasing lengths for y in irange(2, inf): # and widths for x in irange(1, y - 1): # compute corresponding z (using p1, p2 & p5) for z in quadratic(4, 4 * x, -2 * x * y, domain="Z"): if not (z > 0): continue # check against p3, p4 if not ((x + y) ** 2 == (y + z) ** 2 + (x + z) ** 2): continue # calculate the length of diagonal through the cuboid h = hypot(x, y, z) d = abs(h - int(h + 0.5)) # check it is within 5cm of a whole number of metres if d > 0.05: continue # lengths of paths for Beth and Sam (b, s) = (x + y, h + z) if verbose: printf("z={z} [x={x} y={y}; h={h:.3f} d={d:.3f}, beth={b} sam={s:.3f}]") yield (x, y, z) # find the first n solutions n = arg(1, 0, int) first(solve(), n)Solution: The barn in 4 metres high.
In fact there is a family of solutions, the program stops after the first (smallest) solution, which is the only reasonable one, where the barn is less 25m high (and the spiders journeys are each less than 100m).
Analytically:
Equating the sum of the first two of the expressions with twice the third, we get:
Then, substituting for x in the first 2 expressions, and equating them:
Hence the barn has dimensions (2z, 3z, z), and the shortest paths have length 5z.
The diagonal across the barn is: √(x² + y² + z²) = √(14z²) = (√14)z.
And we want to know when this is within 5cm if a whole number of metres.
Here is a shorter and faster program to generate solutions:
Run [ @replit ]
from enigma import (irange, inf, sqrt, first, arg, printf) def solve(): r14 = sqrt(14) for z in irange(1, inf): h = z * r14 d = abs(h - int(h + 0.5)) if d > 0.05: continue (x, y) = (2 * z, 3 * z) (b, s) = (x + y, h + z) printf("z={z} [x={x} y={y}; h={h:.3f} d={d:.3f}; beth={b} sam={s:.3f}]") yield (x, y, z) # find the first n solutions n = arg(1, 0, int) first(solve(), n)LikeLike