Brain-Teaser 692: First-class post
From The Sunday Times, 20th October 1974 [link]
On Trafalgar Day each of the five Sea Lords will take over a post now occupied by one of the others. Each predicts what will happen; those whose predictions are right will get more senior posts, and those whose predictions are wrong will get more junior posts.
The most junior speaks first:
Fifth Sea Lord: “Two Sea Lords will make a direct exchange.”
Fourth Sea Lord: “The Third Sea Lord will become the Second Sea Lord.”
Third Seal Lord: “A man who makes a true prediction will take over my job.”Of the First and Second Sea Lords each predicts the same future new post for himself.
Which post is that?
This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 1 (1980). The puzzle text above is taken from the book.
[teaser692]
Jim Randell 9:23 am on 16 February 2021 Permalink |
If the First Sea Lord and the Second Sea Lord both predict taking on the same position, I am assuming that the position cannot be that of the First or Second Sea Lord, as then one of them would have made a prediction that was impossible to fulfil (because no-one keeps their position).
This Python program runs in 53ms.
Run: [ @repl.it ]
from enigma import subsets, peek, map2str, printf # positions pos = (1, 2, 3, 4, 5) # check <n> makes statement <s> is valid in map <m> check = lambda m, n, s: (m[n] < n) == bool(s) # find an index that maps to x find = lambda m, x: peek(k for (k, v) in m.items() if v == x) # consider derangements for s in subsets(pos, size=len, select="D"): m = dict(zip(pos, s)) # check the statements: # 5: "two will make a direct exchange" if not check(m, 5, (any(m[v] == k for (k, v) in m.items()))): continue # 4: "3 -> 2" if not check(m, 4, (m[3] == 2)): continue # 3: "a man who makes a true prediction (so is promoted) will take # over my job (= 3)" if not check(m, 3, (find(m, 3) > 3)): continue # 1: "1 -> x", 2: "2 -> x" for x in pos: if x == 1 or x == 2: continue if not(check(m, 1, (m[1] == x)) and check(m, 2, (m[2] == x))): continue printf("x={x}; {m}", m=map2str(m, arr="->"))Solution: The First and Second Sea Lords both predicted they would take on the role of Third Sea Lord.
There are two possible maps:
In both scenarios the First and Second Sea Lords are demoted (so made false predictions), and the Third, Fourth and Fifth Sea Lords are promoted (and so made true predictions).
LikeLike
Frits 10:54 am on 19 February 2021 Permalink |
from enigma import SubstitutedExpression def twoswap(a, b): z = [tuple(sorted((x, y))) for (x, y) in zip(a, b)] return len(set(z)) < len(z) # the alphametic puzzle p = SubstitutedExpression( [ # (1, 2, 3, 4, 5) --> (V, W, X, Y, Z) "sorted([V, W, X, Y, Z]) == [1, 2, 3, 4, 5]", # 5: "two will make a direct exchange "twoswap([1, 2, 3, 4, 5], [V, W, X, Y, Z])", # 4: "3 -> 2" "(X == 2 and Y < 4) or (Y == 5 and X != 2)", # 3: "a man who makes a true prediction (so is promoted) will take # over my job (= 3)" "[V, W, X, Y, Z].index(3) > 2 if X < 3 else [V, W, X, Y, Z].index(3) < 3", ], digits=range(1, 6), answer="{3, 4, 5}.difference({V, W})", env=dict(twoswap=twoswap), # derangement # 1: "1 -> x", 2: "2 -> x", x > 2 # we only know both statements have to be false d2i={1 : "VW", 2 : "VW", 3 : "X", 4 : "Y", 5 : "Z"}, distinct="VWXYZ", verbose=0) # print answers answs = set([list(y)[0] for _, y in p.solve()]) for ans in answs: print(f"post = {ans}")LikeLike
Frits 11:15 am on 19 February 2021 Permalink |
@Jim, do you agree with V > 2 and W > 2 for 1: “1 -> x”, 2: “2 -> x”?
We only know both statements to be false.
LikeLike
Jim Randell 11:39 am on 19 February 2021 Permalink |
@Frits: I don’t see how to determine the required answer from the output of your program.
LikeLike
John Crabtree 4:37 pm on 19 February 2021 Permalink |
Here are a couple of ways to tackle it manually.
The 5th SL must be correct. There are three cases to consider:
3rd wrong, and so the 4th is wrong: 4 -> 5, 3 -> 4, 1/2 -> 3 with no possible exchange
3rd right, 4th wrong: 3 -> 1, 4 -> 5, 5 -> 3, with no possible exchange
3rd right, 4th right: 3 -> 2, 4/5 -> 3, 2 -> 4/5 (to allow an exchange), 5/4 -> 1, 1 -> 5/4
1st and 2nd become 4th and 5th or vice versa. Assuming that a SL could not predict his current position, the 1st and 2nd SLs predicted that they would be 3rd Sea Lord.
Using Boolean algebra, where 12 means 1 moves to 2 is true,
5th SL: the statement is true
4th SL: (41+43).32 + 45.(31+34) = 1
3rd SL: (31+32).(43+53) + (34+35).(13+23) = 1
Multiplying the two and removing impossible terms gives:
41.32.53 + 43.32 + 45.31.53 + 45.34.(13+23) = 1
These are the same four possibilities shown in the first solution. The last two do not allow an exchange. From the 5th SL:
14.41.32.53 + 15.51.43.32 = 1, ie
14.41.32.53.25 + 15.51.43.32.24 = 1, with the rest as before.
LikeLike