Teaser 2618: Antics on the block
From The Sunday Times, 25th November 2012 [link] [link]
A wooden cuboid-shaped block has a square base. All its sides are whole numbers of centimetres long, with the height being the shortest dimension. Crawling along three edges, an ant moves from a top corner of the block to the furthest-away bottom corner. In so doing it travels ten centimetres further than if it had chosen the shortest route over the surface of the block.
What are the dimensions of the block?
[teaser2618]



Jim Randell 9:25 am on 6 December 2024 Permalink |
If the square base has dimensions x by x, and the block has height h, where h < x.
Opening up the cuboid like a cardboard box gives us the minimal distance = hypot(x, x + h).
This gives a straightforward program:
from enigma import (irange, ihypot, printf) # consider the size of the square for x in irange(2, 16): # consider the height for h in irange(1, x - 1): # shortest distance d = ihypot(x, x + h) if not d: continue if h + 2 * x == d + 10: printf("{x} x {x} x {h}")Solution: The block is: 15 cm × 15 cm × 5 cm.
With a little analysis we can get a shorter program.
We have:
So, by considering possible values of h, we get a quadratic in x, which can be solved for integer values.
from enigma import (irange, quadratic, printf) # consider increasing heights for h in irange(1, 16): # find integer x values for x in quadratic(1, h - 20, 10 * (5 - h), domain='Z'): if x > h: printf("{x} x {x} x {h}")LikeLike