Teaser 3007: Paving stones
From The Sunday Times, 10th May 2020 [link]
James has decided to lay square block paving stones on his rectangular patio. He has calculated that starting from the outside and working towards the middle that he can lay a recurring concentric pattern of four bands of red stones, then three bands of grey stones, followed by a single yellow stone band. By repeating this pattern and working towards the centre he is able to finish in the middle with a single line of yellow stones to complete the patio.
He requires 402 stones to complete the first outermost band. He also calculates that he will require exactly 5 times the number of red stones as he does yellow stones.
How many red stones does he require?
[teaser3007]
Jim Randell 4:33 pm on 7 May 2020 Permalink |
Assuming an x by y rectangle, with x > y.
If there are k repeats of the (red, grey yellow) bands, then y = 16k − 1.
And the first band of red stones requires 2x + 2y − 4 = 402 stones, so x + y = 203.
Here is a constructive program that counts the number of stones in each band. It runs in 78ms.
Solution: James requires 5520 red stones.
The patio consists of 6 red/grey/yellow layers, finishing with a single row of 14 yellow stones:
The number of stones required is: red = 5520, grey = 3636, yellow = 1104; total = 10260.
The outer band measures 108×95 stones.
LikeLike
Jim Randell 9:33 am on 10 May 2020 Permalink |
Each band requires 8 fewer stones than the previous band, so we can just start with the outermost band (402 stones) and work our way in. When we get to the number blocks for the yellow band we can adjust the number to account for a single line to see if we have reached the middle of the design, and if not carry on. We don’t need to do any analysis to work out the dimensions of the patio, or consider the number of repeats.
This gives us a simpler, and slightly shorter, program.
Run: [ @repl.it ]
LikeLike