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 |
# flatten a list of lists flatten = lambda group: [x for g in group for x in g] M = 50 # maximum age + 1 # formula area average: (n + 2) (3n + 1) / 12 (credit: Jim Randell) # To get a whole number area average, (credit: Tony Brooke-Taylor) # n must satisfy the requirement that (n + 2)(3n + 1) mod 12 = 0. # This requires that n be equal to either 1 + 12i or 10 + 12i (i=0,1,…). # generate list of area averages per age avgs = [] for age in range(1, M): if age % 12 not in {1, 10}: avgs.append(0) else: nbr_tiles = age * (age + 1) // 2 avgs.append(sum([x * x * (x + 1) // 2 for x in range(1, M)][:age]) / nbr_tiles) # generate list of areas per age areas = [] for age in range(1, M): if age % 12 not in {1, 10}: areas.append([0]) else: areas.append(flatten([[x * y for y in range(1, x + 1)] for x in range(1, M)][:age])) ages = [] for i in range(0, M - 1, 3): # check for whole number averages which exist more than once in if avgs[i] > 0 and areas[i].count(avgs[i]) > 1: ages.append(i + 1) print("age(s):", *ages) |

or

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 |
# formula area average: (n + 2) (3n + 1) / 12 (credit: Jim Randell) # n = (sqrt(144 * avg + 25) - 7) / 6 is a solution for # avg(n) = (n + 2) (3n + 1) / 12 from math import ceil divs = [] # check all possible averages (avg(49) = 629) for avg in range(1, 630): (age, r) = divmod((144 * avg + 25) ** 0.5 - 7, 6) if r: continue # check divisor pairs of where both divisors are less equal to for d in range(ceil(avg / age), int(avg ** 0.5) + 1): # divisor? if not avg % d: divs.append([int(age), d]) ages = set() # check ages for which at least 2 entries exist for d1 in divs: if sum(1 for d2 in divs if d1[0] == d2[0]) > 1: ages.add(d1[0]) print("age(s):", *ages) |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
def solve(): ages = [] nbr, tiles, area = 0, [], 0 # consider the artist's age for age in range(1, 50): # accumulate the list of tile areas tiles.extend(age * x for x in range(1, age + 1)) # accumulate the number of tiles nbr += age # accumulate the total area of the tiles area += age * age * (age + 1) // 2 # find the (integer) average area av_area, r = divmod(area, nbr) # look for two or more tiles with this area if not r and tiles.count(av_area) >= 2: ages.append(age) return ages for age in solve(): print(f"Age = {age}") |

Runs in 145 microseconds.

]]>You can also do the x-loop later as the first check doesn’t deal with x.

It turns out only one value of y is possible.

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 |
# the rectangle dimensions and the # pie slice area in 1/2 cm^2 units W, H, A = 20, 13, 104 # try rectangular pie in both orientations for X, Y in ((W, H), (H, W)): # consider the position of the internal # point from the left edge ... for x in range(1, (X + 1) // 2): # ... and from the top edge for y in range(1, (Y + 1) // 2): # form a triangle slice on the bottom edge # with a base of length b b, r = divmod(A, Y - y) if r: continue # position it on the bottom edge for a in range(1, X - b): # form a pie slice on the right edge c, r = divmod(A - (X - a - b) * (Y - y), X - x) if r or not 0 < c < Y: continue # form a pie slice on the top edge d, r = divmod(A - (Y - c) * (X - x), y) if r or not 0 < d < X: continue # form a pie slice on the left edge e, r = divmod(A - (X - d) * y, x) if r or not 0 < e < Y: continue # check that the final slice area is correct if (Y - e) * x + a * (Y - y) != A: continue # the edge distances to the slice lines from the top # left corner clockwise ep = [X - d, Y - c, (X - a - b, X - a), Y - e] print(f"(x, y) = ({x}, {y}); slice edges clockwise {ep}") |

It would not be wise to bet someone that they cannot do something.

Either thay can or they are unlikely to honour the bet.

Clearly you do not need to be certain there there is only one solution.

You might or might not want to.

being only one solution? Yes. Would I bet £1,000,000? Not without producing

an analytical solution.

But do I need to be confident that there is only one solution?

Teasers are designed to have only one solution and this means that the only

risk I take in delivering the first solution is that I will have failed to

solve a flawed teaser. And I can live with that! (I did, of course, check

for other solutions).

How can you be sure there is only one solution?

]]>