From The Sunday Times, 17th February 1980 [link]
Last summer, for a pleasant holiday pastime with mathematical connections, I took up the job of operating our local cricket scoreboard at matches.
This scoreboard is the envy of all the other teams in the league. It shows:
– the two batsmen identified by their numbers in the batting order, with their individual totals;
– the score (i.e. the number of runs and the wickets fallen);
– the number of overs bowled;
– the number of extras;
– the score of the last man out.
During one match, while the two batsmen were in full flight, our team declared their innings closed at the end of an over, with wickets to spare. Exhausted after a busy day, I examined the board and was amazed to see that all of the numbers recorded on it used only two different digits between them.
I noted that the total was the only three-figure number; that there were four two-figure numbers; and that two single-figure numbers appeared twice. I also observed that the score of the last man out was a factor of the total, and the division of the latter by the former still resulted in a single figure number on the board.
I was pleased to see that all the batsmen on the board reached double figures.
What was the final score, i.e. how many runs for how many wickets?
How many extras were there?
[In cricket, the batsmen are numbered from 1 upwards as they come in to bat. The world record is 77 runs in one over. The match itself was perfectly normal — no-one retired hurt etc. Ed.]
This puzzle is included in the book The Sunday Times Book of Brainteasers (1994). The puzzle text above is taken from the book.
[teaser917]
Jim Randell 4:58 pm on 1 September 2023 Permalink |
See also: Tantalizer 8.
This Python program runs in 126ms. (Internal runtime is 72ms).
Run: [ @replit ]
from enigma import (irange, subsets, cproduct, multiset, map2str, seq2str, printf) # multiple lookups on dict <d> def nget(d, k, n): for _ in irange(1, n): k = d[k] return k # male and female labels (male, female) = ("JKLM", "STUV") # each chooses a member of the opposite gender choose = lambda vs, k: subsets(vs, size=k, select='M') for (ms, fs) in cproduct([choose(female, len(male)), choose(male, len(female))]): # map label to choice m = dict(zip(male + female, ms + fs)) # check the conditions: if not nget(m, 'J', 2) == 'K': continue if not nget(m, 'L', 3) == 'S': continue if not nget(m, 'T', 4) == 'U': continue # count the votes vote = multiset.from_seq(m.values()) # exactly 2 people got fewer votes than their choice if not sum(vote.count(k) < vote.count(v) for (k, v) in m.items()) == 2: continue # output voting map printf("{m}", m=map2str(m, arr="->")) # find max votes for a female t = max(vote.count(k) for k in female) # output winner for w in female: if vote.count(w) == t: vs = list(k for (k, v) in m.items() if v == w) printf("-> winner = {w} [choice of {vs}]", vs=seq2str(vs, enc="")) printf()Solution: (a) Una was made chairperson. (b) Jingo and King voted for her.
The votes are:
L and M voted for S and V in some order.
K and U got 2 votes each. And L, M, S, V got 1 vote each.
LikeLike
Frits 8:14 pm on 1 September 2023 Permalink |
Without a function for multiple lookup.
from itertools import product # male and female labels (male, female) = ("JKLM", "STUV") # all possible votes for men ms = [m for m in product(female, repeat=4) if 'S' in m and 'U' in m] # all possible votes for women fs = [f for f in product(male, repeat=4) if 'K' in f] # remove entries where 3 or more people nobody votes for votes = [(m, f) for m, f in product(ms, fs) if len(set(m + f)) > 5] # Jingo's choice's choice was King, J -> f? -> K votes = [(m, f) for m, f in votes if f[female.index(m[0])] == 'K'] # Ling's choice's choice's choice was Sheena L -> f? -> m? -> S votes = [(m, f) for m, f in votes if m[male.index(f[female.index(m[2])])] == 'S'] # Tina's choice's choice's choice's choice was Una, T -> m? -> f? -> m? -> U votes = [(m, f) for m, f in votes if m[male.index(f[female.index(m[male.index(f[1])])])] == 'U'] # exactly 2 people got fewer votes than their choice for m, f in votes: d = dict() # build frequency dictionary for i in range(4): d[male[i]] = f.count(male[i]) d[female[i]] = m.count(female[i]) # count the number of people who got fewer votes than their choice c = sum((d[male[i]] < d[m[i]]) + (d[female[i]] < d[f[i]]) for i in range(4)) if c == 2: mx = max([(d[w], w) for w in female]) print(f"That was {mx[1]}, voted for by " f"{' and '.join(male[i] for i, x in enumerate(m) if x == mx[1])}" f", {m}, {f}")LikeLike
Frits 11:15 pm on 1 September 2023 Permalink |
from enigma import SubstitutedExpression # male and female labels (male, female) = ("JKLM", "STUV") # the alphametic puzzle p = SubstitutedExpression( [ # Jingo's choice's choice was King, J -> f? -> K "(f := [S, T, U, V])[J] == 1", # Ling's choice's choice's choice was Sheena, L -> f? -> m? -> S "(m := [J, K, L, M])[f[L]] == 0", # Tina's choice's choice's choice's choice was Una, T -> m? -> f? -> m? -> U "m[f[m[T]]] == 2", # exactly 2 people got fewer votes than their choice "sum((f.count(i) < m.count(m[i])) if i < 4 else \ (m.count(i - 4) < f.count(f[i - 4])) for i in range(8)) == 2", ], answer="m, f", distinct="", digits=range(4), reorder=0, verbose=0, # use 256 to see the generated code ) # print answers for ans in p.answers(): # build frequency dictionary d = {i: ans[0].count(i) for i in range(4)} mx = max([(d[i], i) for i in range(4)]) print(f"That was {female[mx[1]]}, voted for by " f"{' and '.join(male[i] for i, x in enumerate(ans[0]) if x == mx[1])}" f", {[female[x] for x in ans[0]]} {[male[x] for x in ans[1]]}")LikeLike