Teaser 2969: Slide rules
From The Sunday Times, 18th August 2019 [link] [link]
Using her ordinary 15cm ruler and Zak’s left-handed 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 digits 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.
[teaser2969]
Jim Randell 10:45 pm on 15 August 2019 Permalink |
This Python program collects possible fractions, and then uses a recursive function to select viable sets that Kaz could have chosen. These sets are then examined to find candidates where the sum is expressed as a fraction consisting of two palindromes.
Run: [ @repl.it ]
from fractions import Fraction as F from enigma import (irange, nsplit, gcd, join, printf) # collect fractions less than 1 fs = list() # consider overlaps from 1 to 15 for n in irange(1, 15): for (a, b) in zip(irange(n, 1, step=-1), irange(1, n, step=1)): if a < b: fs.append((a, b)) # generate sets of fractions, using the digits in ds, and: # one of the fractions consists of consecutive numbers # two of the fractions are in lowest terms def choose(fs, ds=set(), ss=[]): # are we done? if not ds: # find fractions in their lowest terms rs = list((a, b) for (a, b) in ss if gcd(a, b) == 1) # there should be exactly 2 of them if len(rs) != 2: return # and exactly one of them must consist of consecutive numbers if sum(b == a + 1 for (a, b) in rs) != 1: return yield ss else: for (i, (a, b)) in enumerate(fs): d = nsplit(a) + nsplit(b) if len(set(d)) < len(d) or not ds.issuperset(d): continue yield from choose(fs[i + 1:], ds.difference(d), ss + [(a, b)]) # check for palindromes def is_palindromic(n): ds = nsplit(n) return ds == ds[::-1] # choose the set of fractions for ss in choose(fs, set(irange(1, 9))): # calculate the sum of the fractions t = sum(F(a, b) for (a, b) in ss) if is_palindromic(t.numerator) and is_palindromic(t.denominator): printf("{ss} = {t}", ss=join((join((a, "/", b)) for (a, b) in ss), sep=" + "))Solution: Zak’s answer is 545/252.
The fractions Kaz has chosen are:
There are 10 sets of fractions that Kaz could have chosen, but only one of these sets has a total consisting of palindromic numerator and denominator when expressed in lowest terms.
LikeLike