1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# Below, rl and rh are the length and height of the covered patio # and at the same time outermost layer of red stones. # m is the number of times the pattern is repeated and n is the # number of stones in the ending line of yellow stones. # sumR and sumY are the number of red and yellow stones used. for m in range(1, 7): for n in range(2, 175): rl, rh = 15 + 16 * (m - 1) + (n - 1), 15 + 16 * (m - 1) if 2 * rl + 2 * rh - 4 == 402: sumR = sum(8 * (32 * i + n - 11) for i in range(1, m + 1)) sumY = sum(2 * (32 * j + n - 33) for j in range(2, m + 1)) + n if sumR == 5 * sumY: print(f"{sumR} red stones were used.") |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
from itertools import count # map the position in the slab colour cycle: # (y, g, g, g, r, r, r, r) to a counter index clr2ctr = {0:0, 1:1, 2:1, 3:1, 4:2, 5:2, 6:2, 7:2} # the number of yellow bricks at the centre # (build from the centre outwards) for n in count(1): # the patio width and height as it grows w, h, = n, 1 # counters for the yellow, grey and red counts # and the area of the previous rectangle ygr, a0 = [0, 0, 0], 0 for cy in count(0): # the current built area (a) and the number # of bricks (nb) in its outer edges a = w * h nb, a0 = a - a0, a # add the number of slabs in the current # band to the appropriate colour counter ygr[clr2ctr[cy % 8]] += nb # are we at the end of four red bands? if cy % 8 == 7: # finish if the last red band used # 402 or more bricks if nb >= 402: break # proceed to the next band w, h = w + 2, h + 2 # there are 402 bricks in the final red band if nb == 402: y, g, r = ygr print(f"red={r}, grey={g}, yellow={y} [height={h}, width=({w}, centre={n})].") break |

Here is a manual solution. Working out from the centre of the patio, let the number of bricks in the single line of yellow bricks be \(n\). The bands of bricks proceed through a repeated cycle of length eight in the colours yellow, grey and red as follows: (y, g, g, g, r, r, r, r). Let \(k\) be the number of completed cycles. After some analysis, the following formulas give the situation at the end of each complete colour cycle:

\[\begin{array}{|l|r|}\hline \text{patio height } (h) & 16k-1\\ \hline \text{patio width } (w) & n+16k-2\\ \hline \text{total yellow bricks } (y) & n+2(k-1)(n+16k-1)\\ \hline \text{total grey bricks } (g )& 6k(n+16k-9) \\ \hline \text{total red bricks } (r) & 8k(n+16k+5)\\ \hline\text{bricks in last red band } (l) & 2(n+32k-5)\\ \hline \end{array}\]We have two equations relating these quantities:\[2(n+ 32k – 5)=402\]\[5\{n + 2(k-1)(n+16k-1)\}=8k(n+16k+5)\]After eliminating \(n\) and simplifying we obtain:\[16k^2-181k+510=0\]

Solving this gives the two roots: \(k=6\) and \(k=85/16\) of which we need the integer valued one: \(k =6\) and \(n = 14\). Plugging into the equation for the number of red bricks used gives the teaser solution as \(5520\).

]]>