Teaser 2974: Flockbuster
From The Sunday Times, 22nd September 2019 [link] [link]
Wu, Xi, Yo and Ze had different two-figure numbers of sheep and kept them in a walled field divided by fences into a fold each. Maths whizz, Wu, with the largest flock, noticed that together her flock and Ze’s equalled Xi’s and Yo’s combined; and that, as a fraction, the ratio of Yo’s flock to Xi’s had consecutive upper and lower numbers (e.g. 3/4), whereas her flock to Xi’s ratio had those numbers swapped over (e.g. 4/3).
Overnight, storm-damaged fences led to the same number of sheep in each fold. Wu’s old maths teacher, told just this number and the above relationships, couldn’t be certain how many sheep Wu owned (which would have been true, also, if he’d been told either fraction instead).
How many sheep did Wu own?
[teaser2974]
Jim Randell 12:07 am on 21 September 2019 Permalink |
This Python program considers possible values for X and Y, from which the values of W and Z (and k) can be derived. It runs in 88ms.
Run: [ @replit ]
from enigma import (irange, subsets, div, filter_unique, unpack, intersect, printf) # collect possible solutions rs = list() # choose X and Y (Y < X) for (Y, X) in subsets(irange(10, 99), size=2): # Y / X can be expressed as k / (k + 1) k = div(Y, X - Y) if k is None: continue # X / W can be expressed as (k + 1) / k W = div((k + 1) * X, k) if W is None or not (X < W < 100): continue # W + Z = X + Y Z = X + Y - W if (not 9 < Z < W) or Z == Y or Z == X: continue # total number of sheep must be divisible by 4 t = W + X + Y + Z if t % 4 != 0: continue rs.append((W, X, Y, Z, k, t)) printf("[Y={Y} X={X}, k={k}, W={W} Z={Z}, t={t}]") # the total is ambiguous (_, rs1) = filter_unique(rs, unpack(lambda W, X, Y, Z, k, t: t)) # the fraction is also ambiguous (_, rs2) = filter_unique(rs, unpack(lambda W, X, Y, Z, k, t: k)) # but together these tell us W rs = intersect((rs1, rs2)) ws = set(W for (W, X, Y, Z, k, t) in rs) printf("W = {ws} [{rs}]")Solution: Wu owns 99 sheep.
There are 12 possible values for W, X, Y, Z that fit the description. Here they are are by the total number of sheep, and the value of k, the numerator of the fraction:
We see that the total number of sheep is only ambiguous when t = 220 (cases 8, 9). So the teacher can narrow down the situation to one of those two cases (all other values of t uniquely identify a single case).
And the value of k is ambiguous when:
k = 2 (cases 6, 9)
k = 3 (cases 2, 5, 10)
k = 4 (case 1, 3, 7)
k = 6 (cases 4, 12)
And case 9 is the only one common to both scenarios so this is the required solution: W=99 Z=11, X=66 Y=44.
So W + Z = X + Y = 110 and Y/X = X/W = 2/3.
LikeLike
Jim Randell 3:06 pm on 22 September 2019 Permalink |
Here’s a slightly shorter program that considers values for X, and derives possible values for W, Y, Z, k, t from that.
Since we know:
We also know that:
So Y and W are divisor pairs of X², and Y < X < W.
We can then also calculate Z and k and check they satisfy the remaining conditions.
Run: [ @replit ]
from enigma import (irange, divisors_pairs, div, filter_unique, unpack, intersect, printf) # collect possible solutions rs = list() # consider 2-digit values for X for X in irange(10, 99): # compute W, Y, Z, k, t for (Y, W) in divisors_pairs(X, 2): if not (9 < Y < X < W < 100): continue Z = X + Y - W if not (9 < Z): continue k = div(Y, X - Y) if k is None: continue t = X + Y + W + Z if t % 4 != 0: continue rs.append((W, X, Y, Z, k, t)) printf("[X={X}, Y={Y} W={W} Z={Z}, k={k} t={t}]") # the total is ambiguous (_, rs1) = filter_unique(rs, unpack(lambda W, X, Y, Z, k, t: t)) # the fraction is also ambiguous (_, rs2) = filter_unique(rs, unpack(lambda W, X, Y, Z, k, t: k)) # but together these tell us W rs = intersect((rs1, rs2)) ws = set(W for (W, X, Y, Z, k, t) in rs) printf("W = {ws} [{rs}]")LikeLike