Teaser 2606: Cue for a queue
From The Sunday Times, 2nd September 2012 [link] [link]
Alan, Brian, Colin, Dave and Ed have surnames Smith, Jones, Rogers, Mason and Hall, but not in that order. They form themselves into a queue. Brian is somewhere ahead of Mr Smith who is somewhere ahead of Ed. Similarly, Mr Jones is ahead of Colin who is ahead of Dave who is ahead of Mr Hall. Mr Mason’s two neighbours in the queue are Alan and Mr Rogers.
If I told you Alan’s surname it would now be possible to work our all their surnames and their positions in the queue.
What is Alan’s surname and what is his position in the queue?
[teaser2606]
Jim Randell 9:20 am on 27 September 2024 Permalink |
I used the [[
SubstitutedExpression]] solver from the enigma.py library to assign positions 1-5 in the queue to the forenames and surnames, such that the required conditions are met.We can then use the [[
filter_unique()]] function to select solutions from the viable assignments, such that knowing Alan’s surname gives a single solution for all names.The following Python program runs in 89ms. (Internal runtime is 5.8ms).
from enigma import (SubstitutedExpression, trim, filter_unique, update, peek, join, printf) # generate possible queues def queues(): # allocate positions 1-5 in the queue to: # # Alan = A; Brian = B; Colin = C; Dave = D; Ed = E # Smith = S; Jones = J; Rogers = R; Mason = M; Hall = H # p = SubstitutedExpression( [ # the surnames are not given in the correct order "A != S or B != J or C != R or D != M or E != H", # B is ahead of S, who is ahead of E "B < S", "S < E", # J is ahead of C, who is ahead of D, who is ahead of H "J < C", "C < D", "D < H", # M's neighbours (on different sides) are A and R "abs(A - R) = 2", "abs(A - M) = 1", "abs(R - M) = 1", ], base=6, digits=[1, 2, 3, 4, 5], distinct=["ABCDE", "SJRMH"], ) # solve the puzzle for s in p.solve(verbose=0): # assemble the queue q = ["??"] * 6 for k in "ABCDE": q[s[k]] = update(q[s[k]], [0], k) for k in "SJRMH": q[s[k]] = update(q[s[k]], [1], k) # return the queue yield trim(q, head=1) # knowing A's surname gives a unique solution f = (lambda q: peek(x for x in q if x[0] == 'A')) for q in filter_unique(queues(), f).unique: printf("{q}", q=join(q, sep=" "))Solution: Alan Smith is second in the queue.
The queue is as follows:
There are 5 candidate solutions:
The first of these is unique for AS. The next two both have AH, and the final two have AJ.
LikeLike
ruudvanderham 5:39 pm on 27 September 2024 Permalink |
import itertools for firstnames, lastnames in zip(itertools.repeat("Alan Brian Colin Dave Ed".split()), itertools.permutations("Smith Jones Rogers Mason Hall".split(), r=5)): for positions in itertools.permutations(range(1, 6)): position = {firstname: position for firstname, position in zip(firstnames, positions)} position.update({lastname: position for lastname, position in zip(lastnames, positions)}) if position["Brian"] < position["Smith"] < position["Ed"]: if position["Jones"] < position["Colin"] < position["Dave"] < position["Hall"]: if {position["Mason"] - position["Alan"], position["Mason"] - position["Rogers"]} == {-1, 1}: if list(lastnames) != "Smith Jones Rogers Mason Hall".split(): for firstname, lastname in zip(firstnames, lastnames): print(f"{firstname+ " "+lastname:12} {position[firstname]} ", end="") print()This prints:
So, it has to be Alan Smith (the others are not unique) and he is in second position.
LikeLike