Sunday Times Teaser 2969 – Slide Rules
by Stephen Hogg
Published August 18 2019 (link)
Using her ordinary 15cm ruler and Zak’s lefthanded version (numbers 1 to 15 reading right to left) Kaz could display various fractions. For instance, putting 5 on one ruler above 1 on the other ruler, the following set of fractions would be displayed: 5/1, 4/2, 3/3, 2/4 and 1/5. Zak listed the fifteen sets starting from “1 above 1” up to “15 above 1”.
Kaz chose some fractions with values less than one from Zak’s sets (using just the numerals 1 to 9, each once only in her selection). Of these, two were in simplest form, one of which had consecutive numerator and denominator. Zak correctly totalled Kaz’s selection, giving the answer as a fraction in simplest form. Curiously, the answer’s numerator and denominator were both palindromic.
Give Zak’s answer.

Erling Torkildsen permalink12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758from math import gcddef Z(a, b, c, d, e, f, g, i):hi = 10 + i# number of fractions in simplest form == 2?t1 = ((gcd(a, b) == 1) + (gcd(c, d) == 1) +(gcd(e, f) == 1) + (gcd(g, hi) == 1)) == 2# numerator and denominator consecutive?t2 = ((b == a + 1) + (d == c + 1) +(f == e + 1) + (hi == g + 1)) == 1N = (a * d * f * hi + c * b * f * hi +e * b * d * hi + g * b * d * f)D = b * d * f * hi# return numerator and denominator in simplest# form and the results of testsreturn (N // gcd(N, D), D // gcd(N, D), t1, t2)# is n a palindrome?def P(n):s = str(n)return len(s) > 1 and s == s[::1]# candidatesXs = set()for a in range(2, 10):for b in range(a + 1, 10):for c in range(2, 10):if c in (a, b):continuefor d in range(c + 1, 10):if d in (a, b):continuefor e in range(2, 10):if e in (a, b, c, d):continuefor f in range(e + 1, 10):if f in (a, b, c, d):continuefor g in range(2, 10):if g in (a, b, c, d, e, f):continuefor i in range(2, 6):if i in (a, b, c, d, e, f, g):continuep, q, t1, t2 = Z(a, b, c, d, e, f, g, i)if P(p)and P(q) and t1 and t2:Xs.add((p, q))if len(Xs) > 1:print("Multiple solutions..")else:X, = Xsprint(f"Zak’s answer: {X[0]}/{X[1]}")