Teaser 2658: Different views
From The Sunday Times, 1st September 2013 [link] [link]
Oliver arranged six [identical standard] dice in a neat pile with three in the bottom row, two in the middle row and one at the top. The faces of these dice were digits rather than the corresponding number of dots. Looking down on them, Beth saw that the five partially-visible tops of the dice contained different digits. In the three rows at the front she saw 1-digit, 2-digit and 3-digit primes, whereas from the back she saw three perfect squares. On the left, working down the three sides, she saw a 3-digit square whereas on the right, again working down, she saw a 3-digit prime.
What was this 3-digit prime?
[teaser2658]





Jim Randell 3:47 pm on 12 December 2023 Permalink |
We need to make some additional assumptions about the dice in order to arrive at a unique solution.
I assumed that the dice are “standard”, i.e. each has the digits 1-6 on, and they are arranged such that opposite faces sum to 7, and the numbers 1, 2, 3 are arranged anti-clockwise around one of the vertices.
I used the [[
Cube()]] class (originally written for Teaser 2835) to generate all possible rotations of a standard die, and then used the [[SubstitutedExpression]] solver from the enigma.py library to solve the puzzle.The following run file executes in 120ms. (Internal runtime of the generated program is 42ms).
Solution: The prime when the pile is viewed from the right is: 523.
From the top the faces form: 31642 (all digits different).
From the front the faces form: 3, 31, 251 (prime numbers).
From the back the faces form: 4, 64, 625 (square numbers).
From the left (top-to-bottom) the faces form: 256 (a square number).
From the right (top-to-bottom) the faces form: 523 (a prime number).
The problem can also be solved with six identical dice where the numbers 1, 2, 3 are arranged clockwise around one of the vertices (i.e. “mirror image” dice), and we get the same result.
But if we are allowed to mix these two types of dice then we can get an additional answer of 653.
And without the additional constraints (i.e. allowing dice where the digits 1-6 appear in any pattern) we can find many possible solutions.
LikeLike
Frits 2:03 pm on 13 December 2023 Permalink |
from itertools import product # get rid of numbers with invalid digits 0,7,8 and 9 or # with digits occuring more than once cleanup = lambda s: {x for x in s if len(set(str(x))) == len(str(x)) and not any(d in str(x) for d in '7890')} oppsides = lambda n: [n, str(7 - int(n))] # given two dice faces anti-clockwise at a vertex, find the third # face anti-clockwise at this vertex (western die if same is true) def die_third_face(first, second, same=False): # credit: B. Gladman if second in (first, 7 - first): raise ValueError t, f = min(first, 7 - first), min(second, 7 - second) c1 = ((f - t) % 3 == (1 if same else 2)) c2 = (first < 4) == (second < 4) return 6 - t - f if c1 == c2 else t + f + 1 # determine valid primes up to 1000 P = {3, 5, 7} P |= {x for x in range(11, 100, 2) if all(x % p for p in P)} P |= {2} | {x for x in range(101, 1000, 2) if all(x % p for p in P)} P = cleanup(P) # determine valid squares up to 1000 sq = cleanup(x * x for x in range(1, 32)) sq3 = [str(x) for x in sq if x > 99] pr3 = [str(x) for x in P if x > 99] # valid prime/square combinations cands = {ln: [(p, s) for s in sq if len(st := str(s)) == ln and (p := (7 * int('111'[:ln]) - int(st[::-1]))) in P and all(len(set(str(x))) == len(st) for x in (s, p))] for ln in (1, 2, 3)} # check all possible combinations for (pt, st), (pm, sm), (pb, sb) in product(*cands.values()): # filter 3-digit squares to have different digits from front and back faces for lft in [s for s in sq3 if all(s[i] not in oppsides(str((pt, pm, pb)[i])[0]) for i in range(3))]: # filter 3-digit primes to have correct hundreds digit rghts = [x for x in pr3 if x[0] == str(7 - int(lft[0]))] # filter 3-digit primes to have different digits from front and back faces for rght in [r for r in rghts if all(r[i] not in oppsides(str((st, sm, sb)[i])[0]) for i in range(3))]: # all visible top faces (left to right) could be seen to be different tp1 = die_third_face(int(lft) % 10, pb // 100) tp2 = die_third_face((int(lft) % 100) // 10, pm // 10) tp3 = die_third_face(pt % 10, int(rght) // 100) tp4 = die_third_face(pm % 10, (int(rght) % 100) // 10) tp5 = die_third_face(pb % 10, int(rght) % 10) if len({tp1, tp2, tp3, tp4, tp5}) == 5: print("answer:", rght)LikeLike