Sunday Times Teaser 3125 – The Bearings’ Trait
by Stephen Hogg
Published Sunday August 14 2022 (link)
At Teaser Tor trig. point I found a geocaching box. The three-figure compass bearings (bearing 000=north, 090=east, etc.) from there to the church spires at Ayton, Beeton and Seaton were needed to decode the clue to the next location.
Each spire lay in a different compass quadrant (eg 000 to 090 is the North-East quadrant). Curiously, each of the numerals 1 to 9 occurred in these bearings and none of the bearings were prime values.
Given the above, if you chose one village at random to be told only its church spire’s bearing, it might be that you could not calculate the other two bearings with certainty, but it would be more likely you could.
Give the three bearings, in ascending order.
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253pr = {3, 5, 7, 11, 13, 17, 19}pr |= {2} | {x for x in range(21, 360, 2) if all(x % p for p in pr)}# the three bearings must lie in the second, third and fourth# quadrants; this means that their left-most digits are 1, 2# and 3 respectively with all other digits being 4 or higher# collect bearing triples and all bearingsbearing_triples, all_bearings = set(), set()# the first bearingfor a in range(145, 180):ad3 = set(int(d) for d in str(a))if 0 in ad3 or len(ad3) != 3 or a in pr:continue# the second bearingfor b in range(245, 270):bd3 = set(int(d) for d in str(b))if 0 in bd3 or len(bd3) != 3 or b in pr:continue# ensure that all digits so far are differentif ad3 & bd3:continueabd6 = ad3 | bd3# the third bearingfor c in range(345, 360):cd3 = set(int(d) for d in str(c))if 0 in cd3 or len(cd3) != 3 or c in pr:continue# ensure all nine digits are differentif abd6 & cd3:continuebearing_triples.add((a, b, c))all_bearings.update((a, b, c))# collect bearings that appear in only one triplet = [s for t in bearing_triples for s in t]special = set(x for x in t if t.count(x) == 1)# if a triple contains more than one special bearing, then# it is more likely than not that one of its bearings will# identify this triplefor triple in bearing_triples:ub = special.intersection(triple)if len(ub) > 1:print(f"Bearings: {triple} (unique: {ub}).")
-
Frits permalink123456789101112131415161718192021222324252627282930313233343536373839404142from itertools import permutationsP = {3, 5, 7, 11, 13, 17, 19}P = {x for x in range(145, 360, 2) if all(x % p for p in P)}# bearings can't reside in the first quadrantthree_bearings = []# a <= 180, b <= 270, c <= 360# select tensfor a2, b2, c2, r in permutations(range(4, 8)):if c2 > 5 or b2 > 6: continue# select unitsfor a3, b3, c3 in permutations([r, 8, 9]):a = 100 + 10 * a2 + a3if a in P: continueb = 200 + 10 * b2 + b3if b in P: continuec = 300 + 10 * c2 + c3if c in P: continue# store possibilitythree_bearings.append({a, b, c})# dictionary: bearing --> three_bearings indexd = {b: [i for i, s in enumerate(three_bearings) if b in s]for b in set(x for s in three_bearings for x in s)}unique_bearings = {k for k, vs in d.items() if len(vs) == 1}# find solutions which have two unique bearings so the chance# of calculating the other two bearings with certainty is 2/3for b3 in three_bearings:ln = len(b3 & unique_bearings)if ln == 3:print(f"no solution, "f"as the other bearings can be calculated with certainty")exit(0)elif ln == 2:print(f"answer : {sorted(b3)}")