Teaser 3009: Head count
From The Sunday Times, 24th May 2020 [link] [link]
My grandson and I play a simple coin game. In the first round we toss seven coins and I predict how many “heads” there will be whilst my grandson predicts the number of “tails”. After the tossing I score a point for each head plus a bonus of ten if my prediction was correct — my grandson scores likewise for the tails. We then repeat this with six coins, then five, and so on down to a single coin. After each round we keep cumulative totals of our scores. In one game, for over half of the pairs of cumulative scores, my grandson’s total was like mine but with the digits in reverse order. In fact he was ahead throughout and at one stage his cumulative total was double mine — and he had an even bigger numerical lead than that on just one earlier occasion and one later occasion.
List the number of heads in each of the seven rounds.
[teaser3009]
Jim Randell 11:03 pm on 22 May 2020 Permalink |
Originally I missed the significance of the word “numerical”, and got no solutions. But careful interpretation of the puzzle text does lead to a single solution.
I wrote a recursive function that keeps track of all the conditions as it goes along.
The following Python 3 program runs in 320ms.
Run: [ @repl.it ]
from itertools import product from enigma import irange, nsplit, join, cached, printf # does A mirror B? mirror = cached(lambda A, B: nsplit(A) == nsplit(B)[::-1]) # play the game starting with a round of k coins, # where A plays heads, B plays tails, and B is always ahead # ms = number of points B is ahead of A # s = index in ms when B = 2A # rv = count number of scores that are reverse of each other def play(k, tA=0, tB=0, ms=[], s=None, rv=0, ss=[]): # are we done? if k == 0: if s is not None and rv > 3: # there must be exactly 1 round after s where B is further ahead if sum(x > ms[s] for x in ms[s + 1:]) == 1: yield ss else: # consider the number of heads, and predictions for heads and tails for (n, h, t) in product(irange(0, k), (0, 1), (0, 1)): # calculate the points for each player a = n + h * 10 b = k - n + t * 10 # and the total points A = tA + a B = tB + b m = B - A # B is always ahead if not(m > 0): continue # look for cases where B = 2A s_ = s if B == 2 * A: # it only happens once if s is not None: continue # there must be exactly 1 previous round where B is further ahead if not(sum(x > m for x in ms) == 1): continue s_ = len(ms) # are A, B mirrored scores? rv_ = rv + mirror(A, B) # in the final 4 rounds we must have encountered some mirrored scores if k < 5 and rv_ < 5 - k: continue # play the remaining rounds yield from play(k - 1, A, B, ms + [m], s_, rv_, ss + [(n, h, t, A, B)]) # play the game, starting with 7 coins for ss in play(7): # output the rounds (pA, pB) = (0, 0) s = list(i for (i, (n, h, t, A, B)) in enumerate(ss) if B == 2 * A)[0] for (i, (n, h, t, A, B)) in enumerate(ss): k = 7 - i fs = [ f"lead = {B - A}" ] if i == s: fs.append("double") if mirror(A, B): fs.append("mirror") printf( "{k} coins: heads={n}; predictions = ({h}, {t}); points = ({a}, {b}); totals = ({A}, {B}); {fs}", a=A - pA, b=B - pB, fs=join(fs, sep="; "), ) (pA, pB) = (A, B) printf()Solution: The number of heads in each of the rounds was: 0, 2, 4, 4, 3, 1, 1.
The full description of the rounds is:
(k = number of coins; h, t = number of heads/tails; H, T = bonus points; a, b = points in round; A, B = cumulative totals)
However, keeping the cumulative totals always using 2 digits gives us three further solutions where the totals 03 and 30 are used as mirrored pairs:
The program will find all 4 solutions if we replace the calls to [[
nsplit(x)]] with [[nsplit(x, 2)]] in the function [[mirror()]] (line 5).LikeLike
Robert Brown 11:57 am on 24 May 2020 Permalink |
Turns out there’s a simple manual solution. After each section (7,6,5 etc) there’s a total sum for all heads & tails. Last digit is different in each case. Adding bonuses makes no difference.
Need to find 4 sections that end in reversible numbers, so just look for reversible pairs where the sum of the pair has the same last digit. Only works for 4 sections, QED.
LikeLike